<commit_before>import React, { PropTypes } from "react";

import Forms from "../../components/forms";
import { Error, Loading, Success } from "../../components/states";

import Validate from "../../util/validate";
import { forceReset } from "../../methods/accounts/browser";

class ForgotPassword extends React.Component {

  static propTypes = {
    save: PropTypes.func.isRequired,
    clear: PropTypes.func.isRequired,
    email: PropTypes.string,
    errors: PropTypes.object.isRequired, // eslint-disable-line
    back: PropTypes.func.isRequired,
  }

  static defaultProps = {
    errors: {},
  }

  state = {
    state: "default",
  }

  isEmail = (value) => {
    const isValid = Validate.isEmail(value);

    if (!isValid) {
      this.props.clear("email");
    } else {
      this.props.save({ email: value });
    }

    return isValid;
  }

  submit = (e) => {
    e.preventDefault();

    this.setState({
      state: "loading",
    });

    Accounts.forgotPassword({
      email: this.props.email,
    }, (err) => {
      if (err) {
        if (err.error === 403) {
          // this user may exist in Rock but not in Apollos
          // we fire a server side check with Rock then on the server
          // we create a user (if they exist in Rock) and email them the reciept
          forceReset(this.props.email, (error) => {
            if (error) {
              this.setState({ state: "error", err: error.message });
              setTimeout(() => {
                this.setState({ state: "default" });
              }, 3000);
              return;
            }

            this.setState({ state: "success" });

            setTimeout(() => {
              this.setState({ state: "default" });
              this.props.back();
            }, 3000);
          });

          return;
        }
        this.setState({ state: "error", err: err.message });
        setTimeout(() => {
          this.setState({ state: "default" });
        }, 3000);
        return;
      }

      this.setState({ state: "success" });

      setTimeout(() => {
        this.setState({ state: "default" });
        this.props.back();
      }, 3000);
    });
  }

  render() {
    const { err } = this.state;

    switch (this.state.state) {
      case "error":
        return <Error msg="Looks like there was a problem" error={err || " "} />;
      case "loading":
        return <Loading msg="Sending email to reset your password..." />;
      case "success":
        return <Success msg={`An email has been sent to ${this.props.email} with instructions on how to reset your password!`} />;
      default:
        return (
          <Forms.Form
            id="forgot-password"<commit_msg>fix line length in forgot password<commit_after>import React, { PropTypes } from "react";

import Forms from "../../components/forms";
import { Error, Loading, Success } from "../../components/states";

import Validate from "../../util/validate";
import { forceReset } from "../../methods/accounts/browser";

class ForgotPassword extends React.Component {

  static propTypes = {
    save: PropTypes.func.isRequired,
    clear: PropTypes.func.isRequired,
    email: PropTypes.string,
    errors: PropTypes.object.isRequired, // eslint-disable-line
    back: PropTypes.func.isRequired,
  }

  static defaultProps = {
    errors: {},
  }

  state = {
    state: "default",
  }

  isEmail = (value) => {
    const isValid = Validate.isEmail(value);

    if (!isValid) {
      this.props.clear("email");
    } else {
      this.props.save({ email: value });
    }

    return isValid;
  }

  submit = (e) => {
    e.preventDefault();

    this.setState({
      state: "loading",
    });

    Accounts.forgotPassword({
      email: this.props.email,
    }, (err) => {
      if (err) {
        if (err.error === 403) {
          // this user may exist in Rock but not in Apollos
          // we fire a server side check with Rock then on the server
          // we create a user (if they exist in Rock) and email them the reciept
          forceReset(this.props.email, (error) => {
            if (error) {
              this.setState({ state: "error", err: error.message });
              setTimeout(() => {
                this.setState({ state: "default" });
              }, 3000);
              return;
            }

            this.setState({ state: "success" });

            setTimeout(() => {
              this.setState({ state: "default" });
              this.props.back();
            }, 3000);
          });

          return;
        }
        this.setState({ state: "error", err: err.message });
        setTimeout(() => {
          this.setState({ state: "default" });
        }, 3000);
        return;
      }

      this.setState({ state: "success" });

      setTimeout(() => {
        this.setState({ state: "default" });
        this.props.back();
      }, 3000);
    });
  }

  render() {
    const { err } = this.state;

    switch (this.state.state) {
      case "error":
        return <Error msg="Looks like there was a problem" error={err || " "} />;
      case "loading":
        return <Loading msg="Sending email to reset your password..." />;
      case "success":
        return (
          <Success
            msg={
              `An email has been sent to ${this.props.email} ` +
              "with instructions on how to reset your password!"
            }
          />
        );
      default:
        return (
          <Forms.Form
            id="forgot-password"
{'fraction_non_alphanumeric': 0.14918032786885246, 'fraction_numerical': 0.0069216757741347905, 'mean_word_length': 1.8333333333333333, 'pattern_counts': {'":': 6, '<': 11, '<?xml version=': 0, '>': 25, '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': '1202084', 'n_tokens_mistral': 1571, 'n_tokens_neox': 1546, 'n_words': 417}