<commit_before>import React from 'react';
import request from 'superagent';
import Spinner from './Spinner';
import Error from './Error';
import {withRouter} from 'react-router';
import '../styles/form.css';

class Login extends React.Component {
    constructor(props) {
        super(props);

        this.state = {
            name: '',
            password: '',
            loading: false,
            error: ''
        };
    }

    handleChange(event) {
        this.setState({[event.target.name]: event.target.value});
    }

    login() {
        this.setState({loading: true});
        request
            .post('https://player.me/api/v1/auth/login')
            .send({
                login: this.state.name,
                password: <PASSWORD>
            })
            .end((err, res) => {
                this.setState({loading: false});
                this.setState({password: ''});

                if (res.ok && res.body.success) {
                    this.props.router.push('post');
                }

                if (err || !res.ok || !res.body.success) {
                    this.error(res.body.results);
                }
            });
    }

    error(message) {
        this.setState({error: message});
        setTimeout(() => {
            this.setState({error: ''})
        }, 5000);
    }

    render() {
        return (
            <div className='form'>
                {this.state.error !== '' ? <Error>{this.state.error}</Error> : null}

                <input value={this.state.name} onChange={this.handleChange.bind(this)} disabled={this.state.loading} name='name' type='text' placeholder='Username or email' />
                <input value={this.state.password} onChange={this.handleChange.bind(this)} disabled={this.state.loading} name='password' type='password' placeholder='Password' />
                {this.state.loading ? <Spinner /> : null}
                <button onClick={this.login.bind(this)} disabled={this.state.loading}>Login</button>
            </div>
        );
    }
}

export default withRouter(Login);
<commit_msg>Use form submit instead of button click.<commit_after>import React from 'react';
import request from 'superagent';
import Spinner from './Spinner';
import Error from './Error';
import {withRouter} from 'react-router';
import '../styles/form.css';

class Login extends React.Component {
    constructor(props) {
        super(props);

        this.state = {
            name: '',
            password: '',
            loading: false,
            error: ''
        };
    }

    handleChange(event) {
        this.setState({[event.target.name]: event.target.value});
    }

    login(event) {
        event.preventDefault();

        this.setState({loading: true});
        request
            .post('https://player.me/api/v1/auth/login')
            .send({
                login: this.state.name,
                password: <PASSWORD>
            })
            .end((err, res) => {
                this.setState({loading: false});
                this.setState({password: ''});

                if (res.ok && res.body.success) {
                    this.props.router.push('post');
                }

                if (err || !res.ok || !res.body.success) {
                    this.error(res.body.results);
                }
            });
    }

    error(message) {
        this.setState({error: message});
        setTimeout(() => {
            this.setState({error: ''})
        }, 5000);
    }

    render() {
        return (
            <form className='form' onSubmit={this.login.bind(this)}>
                {this.state.error !== '' ? <Error>{this.state.error}</Error> : null}

                <input value={this.state.name} onChange={this.handleChange.bind(this)} disabled={this.state.loading} name='name' type='text' placeholder='Username or email' />
                <input value={this.state.password} onChange={this.handleChange.bind(this)} disabled={this.state.loading} name='password' type='password' placeholder='Password' />
                {this.state.loading ? <Spinner /> : null}
                <button type='submit' disabled={this.state.loading}>Login</button>
            </form>
        );
    }
}

export default withRouter(Login);

{'fraction_non_alphanumeric': 0.15667767815007078, 'fraction_numerical': 0.0023596035865974517, 'mean_word_length': 1.7924901185770752, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 27, 'https://': 2, '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': '5173817', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1135, 'n_words': 208}