<commit_before>/**
* ForgotPasswordPanel.jsx
* Created by <NAME> 2/23/16
**/

import React, { PropTypes } from 'react';
import { hashHistory } from 'react-router';
import { kGlobalConstants } from '../../GlobalConstants.js';
import Username from '../login/Username.jsx';
import SignInButton from '../login/SignInButton.jsx';
import ErrorMessage from '../SharedComponents/ErrorMessage.jsx';
import SuccessMessage from '../SharedComponents/SuccessMessage.jsx';

import * as LoginHelper from '../../helpers/loginHelper.js';

const propTypes = {
    message: PropTypes.string
};

export default class ForgotPasswordPanel extends React.Component {
    constructor(props) {
        super(props);

        this.state = {
            username: '',
            requestSent: false,
            resetFailed: false,
            buttonText: 'Reset',
            buttonDisabled: false,
            hideButton: false
        };
    }

    requestReset() {
        this.setState({
            buttonText: 'Submitting...',
            buttonDisabled: true
        });

        LoginHelper.requestPasswordToken(this.state.username)
            .then(() => {
                this.setState({
                    requestSent: true,
                    resetFailed: false,
                    hideButton: true,
                    buttonText: 'Reset',
                    buttonDisabled: false
                });
            })
            .catch((err) => {
                this.setState({
                    requestSent: true,
                    resetFailed: true,
                    hideButton: false,
                    buttonText: 'Reset',
                    buttonDisabled: false
                });
            });
    }

    handleKeyPress(e) {
        const enterKey = 13;
        if (e.charCode === enterKey) {
            e.preventDefault();
            this.requestReset();
        }
    }

    handleUsernameChange(e) {
        this.setState({
            username: e.target.value
        });
    }

    render() {
        let messageComponent = null;

        if (this.state.requestSent) {
            if (this.state.resetFailed) {
                messageComponent = <ErrorMessage message={"If this email address has a user account, you will receive an email shortly. Don't forget to check your spam folder for messages from the DATA Act Broker."} />;
            } else {
                messageComponent = <SuccessMessage message={"You will receive an email shortly. Don't forget to check your spam folder for messages from the DATA Act Broker."} />;
            }
        } else if (this.props.message) {
            messageComponent = <ErrorMessage message={this.props.message} />;
        }

        let hideButton = '';
        if (this.state.hideButton) {
            hideButton = 'hide';
        }

        return (
            <div className="col-md-5 usa-da-login-container"><commit_msg>Update ForgotPasswordPanel.jsx<commit_after>/**
* ForgotPasswordPanel.jsx
* Created by <NAME> 2/23/16
**/

import React, { PropTypes } from 'react';
import { hashHistory } from 'react-router';
import { kGlobalConstants } from '../../GlobalConstants.js';
import Username from '../login/Username.jsx';
import SignInButton from '../login/SignInButton.jsx';
import ErrorMessage from '../SharedComponents/ErrorMessage.jsx';
import SuccessMessage from '../SharedComponents/SuccessMessage.jsx';

import * as LoginHelper from '../../helpers/loginHelper.js';

const propTypes = {
    message: PropTypes.string
};

export default class ForgotPasswordPanel extends React.Component {
    constructor(props) {
        super(props);

        this.state = {
            username: '',
            requestSent: false,
            resetFailed: false,
            buttonText: 'Reset',
            buttonDisabled: false,
            hideButton: false
        };
    }

    requestReset() {
        this.setState({
            buttonText: 'Submitting...',
            buttonDisabled: true
        });

        LoginHelper.requestPasswordToken(this.state.username)
            .then(() => {
                this.setState({
                    requestSent: true,
                    resetFailed: false,
                    hideButton: true,
                    buttonText: 'Reset',
                    buttonDisabled: false
                });
            })
            .catch((err) => {
                this.setState({
                    requestSent: true,
                    resetFailed: true,
                    hideButton: false,
                    buttonText: 'Reset',
                    buttonDisabled: false
                });
            });
    }

    handleKeyPress(e) {
        const enterKey = 13;
        if (e.charCode === enterKey) {
            e.preventDefault();
            this.requestReset();
        }
    }

    handleUsernameChange(e) {
        this.setState({
            username: e.target.value
        });
    }

    render() {
        let messageComponent = null;

        if (this.state.requestSent) {
            messageComponent = <SuccessMessage message={"If this email address has a user account, you will receive an email shortly. Don't forget to check your spam folder for messages from the DATA Act Broker."} />;
        } else if (this.props.message) {
            messageComponent = <ErrorMessage message={this.props.message} />;
        }

        let hideButton = '';
        if (this.state.hideButton) {
            hideButton = 'hide';
        }

        return (
            <div className="col-md-5 usa-da-login-container">
{'fraction_non_alphanumeric': 0.11071042192571222, 'fraction_numerical': 0.00288496213487198, 'mean_word_length': 1.6732530120481928, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2492878', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1364, 'n_words': 345}