<commit_before>/* eslint-disable no-use-before-define */
import React from 'react-native';
import { MKButton } from 'react-native-material-kit';
import { login, colors } from '../assets/styles';
import EmailInput from './email_input';
import PasswordInput from './password_input';
import NavBar from './navbar';
import Validator from 'email-validator';
import owasp from 'owasp-password-strength-test';
import Keychain from 'react-native-keychain';
import ip from '../config';

const {
  Component,
  PropTypes,
  View,
  Text,
} = React;

const CustomButton = new MKButton.Builder()
  .withStyle(login.button)
  .build();

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

    this.state = {
      email: '',
      password: '',
      strongPassword: false,
    };

    owasp.config({
      allowPassphrases: true,
      maxLength: 128,
      minLength: 6,
      minPhraseLength: 10,
      minOptionalTestsToPass: 3,
    });

    this.onPress = this.onPress.bind(this);
    this.onBack = this.onBack.bind(this);
    this.onTypeEmail = this.onTypeEmail.bind(this);
    this.onTypePassword = this.onTypePassword.bind(this);
  }

  onPress() {
    const emailToLowercase = this.state.email.toLowerCase();
    if (this.props.loginOrSignup === 'login') {
      this.props.loginUser(emailToLowercase, this.state.password)
        .then(() => {
          if (this.props.token) {
            Keychain.setInternetCredentials(`${ip}`, JSON.stringify(this.props.user), '')
              .then(() => {
                this.props.navigator.resetTo({ name: 'home' })
              });
          }
        });
    } else {
      if (!Validator.validate(this.state.email)) {
        console.log(this.state.email, ' is invalid, please try again.');
      } else {
        this.props.signupUser(emailToLowercase, this.state.password)
        .then(() => {
          if (this.props.token) {
            Keychain.setInternetCredentials(`${ip}:8000`, this.props.username, this.props.token)
              .then(() => {
                this.props.navigator.replace({ name: 'username' });
              });
          }
        });
      }
    }
  }

  onBack() {
    this.props.navigator.pop();
  }

  onTypeEmail(email) {
    return this.setState({ email });
  }

  onTypePassword(password) {
    const result = owasp.test(password);
    this.setState({ password, strongPassword: result.strong });
  }

  render() {
    let strongPasswordMessage = <Text />;
    if (!this.state.strongPassword && this.state.password) {
      strongPasswordMessage = <Text>Weak Password!</Text>;<commit_msg>password strength should not be judged on login<commit_after>/* eslint-disable no-use-before-define */
import React from 'react-native';
import { MKButton } from 'react-native-material-kit';
import { login, colors } from '../assets/styles';
import EmailInput from './email_input';
import PasswordInput from './password_input';
import NavBar from './navbar';
import Validator from 'email-validator';
import owasp from 'owasp-password-strength-test';
import Keychain from 'react-native-keychain';
import ip from '../config';

const {
  Component,
  PropTypes,
  View,
  Text,
} = React;

const CustomButton = new MKButton.Builder()
  .withStyle(login.button)
  .build();

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

    this.state = {
      email: '',
      password: '',
      strongPassword: <PASSWORD>,
    };

    owasp.config({
      allowPassphrases: true,
      maxLength: 128,
      minLength: 6,
      minPhraseLength: 10,
      minOptionalTestsToPass: 3,
    });

    this.onPress = this.onPress.bind(this);
    this.onBack = this.onBack.bind(this);
    this.onTypeEmail = this.onTypeEmail.bind(this);
    this.onTypePassword = this.onTypePassword.bind(this);
  }

  onPress() {
    const emailToLowercase = this.state.email.toLowerCase();
    if (this.props.loginOrSignup === 'login') {
      this.props.loginUser(emailToLowercase, this.state.password)
        .then(() => {
          if (this.props.token) {
            Keychain.setInternetCredentials(`${ip}`, JSON.stringify(this.props.user), '')
              .then(() => {
                this.props.navigator.resetTo({ name: 'home' })
              });
          }
        });
    } else {
      if (!Validator.validate(this.state.email)) {
        console.log(this.state.email, ' is invalid, please try again.');
      } else {
        this.props.signupUser(emailToLowercase, this.state.password)
        .then(() => {
          if (this.props.token) {
            Keychain.setInternetCredentials(`${ip}:8000`, this.props.username, this.props.token)
              .then(() => {
                this.props.navigator.replace({ name: 'username' });
              });
          }
        });
      }
    }
  }

  onBack() {
    this.props.navigator.pop();
  }

  onTypeEmail(email) {
    return this.setState({ email });
  }

  onTypePassword(password) {
    const result = owasp.test(password);
    this.setState({ password, strongPassword: result.strong });
  }

  render() {
    let strongPasswordMessage = <Text />;
    if (!this.state.strongPassword && this.state.password && this.props.loginOrSignup !== 'login') {
      strongPasswordMessage = <Text>Weak Password!</Text>;
{'fraction_non_alphanumeric': 0.14883102071849458, 'fraction_numerical': 0.004181714502946208, 'mean_word_length': 2.6189821182943605, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 18, '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': '5366116', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1585, 'n_words': 308}