<commit_before>import React from 'react';
import api from '../utils/api';

class Login extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      username: '',
      password: '',
      error: false,
      isLoading: false
    };
  }

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

  handlePasswordChange(event) {
    this.setState({password: event.target.value});
  }

  handleSubmit(){
    // Invoke controller to send POST request
    console.log(this.state);

    api.login(this.state.username, this.state.password)
      .then((response) => {
        if(response.status === 400){
          this.setState({
             error: 'Username or password is incorrect',
             isLoading: false
           });
          console.log(this.state.error);
        } else if (response.status === 200) {
          response.json().then(function(body){
            console.log(body);
            this.setState({
             error: false,
             isLoading: false
           });
            // pass these to teacher dashboard component:
            // classes: body.teacher.classes,
            // userId: body.teacher.uid

            // Redirect to teacher dashboard
            // userId: body.teacher.uid
            // classes: body.teacher.classes,
          });
        }
      })
      .catch((err) => {
        this.setState({
           error: 'User not found' + err,
           isLoading: false
         });
        console.log(this.state.error)
      });
      this.setState({
        isLoading: false,
        username: '',
        password: ''
      });
  }

  render(){
    var showErr = this.state.error ? <div> {this.state.error} </div> : <div></div>;
    return (
      <div>
        <h1>Login</h1>
        <input
        type="text" 
        placeholder="Username" 
        value={this.state.username} 
        onChange={this.handleUsernameChange.bind(this)} 
        />
        <input
        type="password" 
        placeholder="Password" 
        value={this.state.password} 
        onChange={this.handlePasswordChange.bind(this)} 
        />
        <button type="button" onClick={this.handleSubmit.bind(this)}>
        Submit
        </button>
        {showErr}
      </div>
    );
  }
}

module.exports = Login;<commit_msg>Render only if user is on 'auth' display<commit_after>import React from 'react';
import api from '../utils/api';

class Login extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      username: '',
      password: '',
      error: false,
      isLoading: false
    };
  }

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

  handlePasswordChange(event) {
    this.setState({password: event.target.value});
  }

  handleSubmit(){
    // Invoke controller to send POST request
    console.log(this.state);
    var that = this;
    api.login(this.state.username, this.state.password)
      .then((response) => {
        if(response.status === 400){
          this.setState({
             error: 'Username or password is incorrect',
             isLoading: false
           });
          console.log(this.state.error);
        } else if (response.status === 200) {
          response.json().then(function(body){
            console.log('body',body);

            that.setState({
              error: false,
              isLoading: false
            });

            that.props.displayListener('home');

            // pass these to teacher dashboard component:
            // classes: body.teacher.classes,
            // userId: body.teacher.uid

            // Redirect to teacher dashboard
            // userId: body.teacher.uid
            // classes: body.teacher.classes,
          });
        }
      })
      .catch((err) => {
        that.setState({
           error: 'User not found' + err,
           isLoading: false
         });
        console.log(this.state.error)
      });
      that.setState({
        isLoading: false,
        username: '',
        password: ''
      });
  }

  render(){
    var showErr = this.state.error ? <div> {this.state.error} </div> : <div></div>;
    if(this.props.display[0] === 'auth') {
      return (
        <div>
          <h1>Login</h1>
          <input
          type="text" 
          placeholder="Username" 
          value={this.state.username} 
          onChange={this.handleUsernameChange.bind(this)} 
          />
          <input
          type="password" 
          placeholder="Password" 
          value={this.state.password} 
          onChange={this.handlePasswordChange.bind(this)} 
          />
          <button type="button" onClick={this.handleSubmit.bind(this)}>
          Submit
          </button>
          {showErr}
        </div>
      );
    } else {
      return (<div></div>);
    }
  }
}

module.exports = Login;
{'fraction_non_alphanumeric': 0.13774048301268932, 'fraction_numerical': 0.0034793286942284077, 'mean_word_length': 1.71650917176209, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 33, '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': '4923651', 'n_tokens_mistral': 1385, 'n_tokens_neox': 1352, 'n_words': 263}