<commit_before>import React, { Component, PropTypes } from 'react';
import { Link } from 'react-router';
import { Headline } from './reusable-components.jsx';
import Paper from 'material-ui/lib/paper';
import TextField from 'material-ui/lib/text-field';
import RaisedButton from 'material-ui/lib/raised-button';
import CircularProgress from 'material-ui/lib/circular-progress';
import auth from '../utils/auth.js';

class SignInPage extends Component {
    constructor(props, context) {
        super(props, context);
        this.state = {
            error: "",
            email: "",
            password: ""
        };
        this.history = props.history;
        this.showSessionMsg = props.location.query ? props.location.query.session : true;
        this._handlePasswordChange = this._handlePasswordChange.bind(this);
        this._handleEmailChange = this._handleEmailChange.bind(this);
        this._formSubmit = this._formSubmit.bind(this);
    }

    _validateEmail(email) {
        var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        return re.test(email);
    }

    _handleEmailChange(e) {
        this.state.errorEmail = "";
        var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        if (!e.target.value) {
            this.state.errorEmail = "This field is required.";
        } else if (!re.test(e.target.value)) {
            this.state.errorEmail = "Email is not valid.";
        }
        this.setState({ errorEmail: this.state.errorEmail,
                        email: e.target.value });
    }

    _handlePasswordChange(e) {
        this.state.errorPassword = "";
        if (!e.target.value) {
            this.state.errorPassword = "<PASSWORD>.";
        } else if (e.target.value.length < 8) {
            this.state.errorPassword = "<PASSWORD>.";
        }
        this.setState({ errorPassword: this.state.errorPassword,
                        password: e.target.value });
    }

    _formSubmit(e) {
        const { errorPassword, errorEmail, email, password } = this.state;
        e.preventDefault();
        if (errorPassword == '' && errorEmail == '') {
            this.setState({ error: <CircularProgress /> });
                auth.login(email, password)
                .then((response) => {
                    console.log("hello from login");
                    localStorage.setItem('token', response.data.authtoken.auth_token);
                    auth.loggedIn()
                    .then(() => {if(false || null || undefined){
                            return this.setState({ error: "Login Failed" });
                        }
                    })
                    .catch((err) => {
                        console.log(err);
                    });
                })
                .catch((err) => {
                    console.log(err)
                });
            setTimeout(() => {
                this.context.router.push('/donation');
            }, 1000);
        }
        else {
            this.setState({ error: 'Can not send request.' })
        }
    }

    render() {
        const { errorPassword, errorEmail, email, password, error } = this.state;
        return (
            <div className="signin text-center text-white">
            <Paper zDepth={1}>
                <div className="container">
                <Headline value="Sign In" />
                <form>
                    <TextField
                        hintText="Enter Email"
                        errorText={errorEmail}
                        floatingLabelText="Email"
                        onChange={this._handleEmailChange}
                        value={email}
                        />
                    <br/>
                    <TextField
                        hintText="Enter Password"
                        errorText={errorPassword}
                        floatingLabelText="Password"
                        onChange={this._handlePasswordChange}
                        value={password}
                        type="password"
                        />
                    <br/>
                    <RaisedButton
                        label="Sign In"
                        secondary={true}
                        onClick={this._formSubmit}
                        />
                        <br/>
                    <span>
                        {error}
                    </span>
                </form>
                </div>
            </Paper>
            </div>
        )
    }
}

SignInPage.contextTypes = {
    router: React.PropTypes.object.isRequired
};
<commit_msg>Refactor: edit style, remove unused tags<commit_after>import React, { Component, PropTypes } from 'react';
import { Link } from 'react-router';
import { Headline } from './reusable-components.jsx';
import Paper from 'material-ui/lib/paper';
import TextField from 'material-ui/lib/text-field';
import RaisedButton from 'material-ui/lib/raised-button';
import CircularProgress from 'material-ui/lib/circular-progress';
import auth from '../utils/auth.js';

class SignInPage extends Component {
    constructor(props, context) {
        super(props, context);
        this.state = {
            error: "",
            email: "",
            password: ""
        };
        this.history = props.history;
        this.showSessionMsg = props.location.query ? props.location.query.session : true;
        this._handlePasswordChange = this._handlePasswordChange.bind(this);
        this._handleEmailChange = this._handleEmailChange.bind(this);
        this._formSubmit = this._formSubmit.bind(this);
    }

    _validateEmail(email) {
        var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        return re.test(email);
    }

    _handleEmailChange(e) {
        this.state.errorEmail = "";
        var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        if (!e.target.value) {
            this.state.errorEmail = "This field is required.";
        } else if (!re.test(e.target.value)) {
            this.state.errorEmail = "Email is not valid.";
        }
        this.setState({ errorEmail: this.state.errorEmail,
                        email: e.target.value });
    }

    _handlePasswordChange(e) {
        this.state.errorPassword = "";
        if (!e.target.value) {
            this.state.errorPassword = "<PASSWORD>.";
        } else if (e.target.value.length < 8) {
            this.state.errorPassword = "Password needs more than 8 characters.";
        }
        this.setState({ errorPassword: this.state.errorPassword,
                        password: e.target.value });
    }

    _formSubmit(e) {
        const { errorPassword, errorEmail, email, password } = this.state;
        e.preventDefault();
        if (errorPassword == '' && errorEmail == '') {
            this.setState({ error: <CircularProgress /> });
                auth.login(email, password)
                .then((response) => {
                    console.log("hello from login");
                    localStorage.setItem('token', response.data.authtoken.auth_token);
                    auth.loggedIn()
                    .then(() => {if(false || null || undefined){
                            return this.setState({ error: "Login Failed" });
                        }
                    })
                    .catch((err) => {
                        console.log(err);
                    });
                })
                .catch((err) => {
                    console.log(err)
                });
            setTimeout(() => {
                this.context.router.push('/donation');
            }, 1000);
        }
        else {
            this.setState({ error: 'Can not send request.' });
        }
    }

    render() {
        const { errorPassword, errorEmail, email, password, error } = this.state;
        return (
            <div className="signin text-center text-white">
                <Headline value="Sign In" />
                <form>
                    <TextField
                        hintText="Enter Email"
                        errorText={errorEmail}
                        floatingLabelText="Email"
                        onChange={this._handleEmailChange}
                        style={{width: '80%', maxWidth: 350}}
                        errorStyle={{color: 'white'}}
                        value={email}
                        />
                    <br/>
                    <TextField
                        hintText="Enter Password"
                        errorText={errorPassword}
                        floatingLabelText="Password"
                        onChange={this._handlePasswordChange}
                        style={{width: '80%', maxWidth: 350}}
                        errorStyle={{color: 'white'}}
                        value={password}
                        type="password"
                        />
                    <br/>
                    <RaisedButton
                        label="Sign In"
                        secondary={true}
                        onClick={this._formSubmit}
                        style={{marginTop: 100, minWidth: 250}}
                        />
                        <br/>
                    <span>
                        {error}
                    </span>
                </form>
            </div>
        )
    }
}

SignInPage.contextTypes = {
    router: React.PropTypes.object.isRequired
};

{'fraction_non_alphanumeric': 0.20534208059981257, 'fraction_numerical': 0.01162136832239925, 'mean_word_length': 1.3931374747701277, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 48, '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': '6633512', 'n_tokens_mistral': 3297, 'n_tokens_neox': 3161, 'n_words': 444}