<commit_before>import React, {Component} from 'react';
import RaisedButton from 'material-ui/RaisedButton';
import FlatButton from 'material-ui/FlatButton';
import Dialog from 'material-ui/Dialog';
import TextField from 'material-ui/TextField';
import * as loginCtrl from './loginCtrl';

class Login extends Component {
  constructor(props, context) {
    super(props, context);
    this.state = {
      username: '',
      email: '',
      password: '',
      loginIsOpen: !loginCtrl.getJwt(),
      isSigningUp: false,
      submitError: ''
    };
  };

  handleLogin = () => {
    var returningUser = {
      email: this.state.email,
      password: <PASSWORD>
    };
    loginCtrl.login(returningUser)
    .then(res => {
      this.setState({
        loginIsOpen: false
      })
    })
    .catch(err => {
      const msg = err.response.data.message;
      this.setState({
        submitError: msg
      });
    })
  };

  handleSignUp = () => {
    var newUser = {
      email: this.state.email,
      username: this.state.username,
      password: <PASSWORD>
    };
    loginCtrl.signup(newUser)
    .then(res => {
      this.setState({
        loginIsOpen: false
      })
    })
    .catch(err => {
      const msg = err.response.data.message;
      this.setState({
        submitError: msg
      });
    })
  };

  handleChange = (name,e) => {
    if (this.state.submitError) {
      this.setState({ submitError: '' });
    }
    this.setState({
      [name]: e.target.value
    });
  };

  toggleSignUp = () => {
    this.setState({
      isSigningUp: !this.state.isSigningUp
    });
  };

  render() {
    const signUp = this.state.isSigningUp;
    const signUpField = signUp ? 
      (<TextField 
        onChange={this.handleChange.bind(this,'username')}
        fullWidth={true}
        hintText='username' />) :
      null;

    const standardActions = [
      <RaisedButton
        label='Login'
        primary={!this.state.isSigningUp}
        onTouchTap={(!signUp) ? 
          this.handleLogin : 
          this.toggleSignUp.bind(this)
        }
      />,
      <RaisedButton
        label='Signup'
        primary={this.state.isSigningUp}
        onTouchTap={(signUp) ? 
          this.handleSignUp :
          this.toggleSignUp.bind(this)
        }
      />
    ];

    return (
          <Dialog
            overlayClassName='hidden'
            open={this.state.loginIsOpen}
            title='Welcome!'
            actions={standardActions}
            modal={true}
          >
            <TextField 
              onChange={this.handleChange.bind(this,'email')}
              fullWidth={true}
              hintText='email' />
            {signUpField}
            <TextField<commit_msg>Tweak login screen for mobile<commit_after>import React, {Component} from 'react';
import RaisedButton from 'material-ui/RaisedButton';
import FlatButton from 'material-ui/FlatButton';
import Dialog from 'material-ui/Dialog';
import TextField from 'material-ui/TextField';
import * as loginCtrl from './loginCtrl';

class Login extends Component {
  constructor(props, context) {
    super(props, context);
    this.state = {
      username: '',
      email: '',
      password: '',
      loginIsOpen: !loginCtrl.getJwt(),
      isSigningUp: false,
      submitError: ''
    };
  };

  handleLogin = () => {
    var returningUser = {
      email: this.state.email,
      password: <PASSWORD>
    };
    loginCtrl.login(returningUser)
    .then(res => {
      this.setState({
        loginIsOpen: false
      })
    })
    .catch(err => {
      const msg = err.response.data.message;
      this.setState({
        submitError: msg
      });
    })
  };

  handleSignUp = () => {
    var newUser = {
      email: this.state.email,
      username: this.state.username,
      password: <PASSWORD>
    };
    loginCtrl.signup(newUser)
    .then(res => {
      this.setState({
        loginIsOpen: false
      })
    })
    .catch(err => {
      const msg = err.response.data.message;
      this.setState({
        submitError: msg
      });
    })
  };

  handleChange = (name,e) => {
    if (this.state.submitError) {
      this.setState({ submitError: '' });
    }
    this.setState({
      [name]: e.target.value
    });
  };

  toggleSignUp = () => {
    this.setState({
      isSigningUp: !this.state.isSigningUp
    });
  };

  render() {
    const signUp = this.state.isSigningUp;
    const signUpField = signUp ? 
      (<TextField 
        onChange={this.handleChange.bind(this,'username')}
        fullWidth={true}
        hintText='username' />) :
      null;

    const standardActions = [
      <RaisedButton
        label='Login'
        primary={!this.state.isSigningUp}
        onTouchTap={(!signUp) ? 
          this.handleLogin : 
          this.toggleSignUp.bind(this)
        }
      />,
      <RaisedButton
        label='Signup'
        primary={this.state.isSigningUp}
        onTouchTap={(signUp) ? 
          this.handleSignUp :
          this.toggleSignUp.bind(this)
        }
      />
    ];

    return (
          <Dialog
            autoDetectWindowHeight={false}
            overlayClassName='hidden'
            open={this.state.loginIsOpen}
            title='Welcome!'
            actions={standardActions}
            modal={true}
          >
            <TextField 
              onChange={this.handleChange.bind(this,'email')}
              fullWidth={true}
              hintText='email' />
            {signUpField}
            <TextField
{'fraction_non_alphanumeric': 0.13436645396536007, 'fraction_numerical': 0.0, 'mean_word_length': 1.936830835117773, 'pattern_counts': {'":': 0, '<': 19, '<?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': '3077831', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1646, 'n_words': 274}