<commit_before>/* global grecaptcha */
import $ from 'jquery';
import React from 'react';

import BaseComponent from '../BaseComponent';
import Helmet from '../Helmet';

import axios from '../../config/axios';
import router from '../../router';
import util from '../util';

const store = {};

class SplashMenu extends BaseComponent {

  constructor(props) {
    super(props);
    this.state = store;

    this.bind('handleLogin', 'handleSignup');
  }

  componentDidMount() {
    $('#signup-form').submit(this.handleSignup);
    $('#login-form').submit(this.handleLogin);

    grecaptcha.render('recaptcha', {
      sitekey: '<KEY>',
    });
  }

  handleLogin(e) {
    e.preventDefault();

    const formData = util.convertQsToObject($('#login-form').serialize());

    axios.post('/user/login', formData)
      .then(({ data }) => {
        switch (data.code) {
          case 200:
            router.setRoute('/loadouts');
            break;
          case 400:
            $('#usernameEmail').select();
            break;
          case 500:
            // TODO: Show an error message
            break;
          default:
        }
      })
      .catch(() => {
        // TODO: Show an error message
      });
  }

  handleSignup(e) {
    e.preventDefault();

    const formData = util.convertQsToObject($('#signup-form').serialize());

    axios.post('/user', formData)
      .then(({ data }) => {
        switch (data.code) {
          case 200:
            router.setRoute('/loadouts');
            break;
          case 400:
            $('#username').select();
            grecaptcha.reset();
            break;
          case 500:
            // TODO: Show an error message
            break;
          default:
        }
      })
      .catch(() => {
        // TODO: Show an error message
      });
  }

  render() {
    return (
      <div>
        <Helmet
          // Include Recaptcha library for signups
          script={[
            { src: 'https://www.google.com/recaptcha/api.js?render=explicit' },<commit_msg>Display errors on Splash Menu with Message component<commit_after>/* global grecaptcha */
import $ from 'jquery';
import React from 'react';

import BaseComponent from '../BaseComponent';
import Helmet from '../Helmet';
import Message from '../Message';

import axios from '../../config/axios';
import router from '../../router';
import util from '../util';

const store = { error: '' };

class SplashMenu extends BaseComponent {

  constructor(props) {
    super(props);
    this.state = store;

    this.bind('handleLogin', 'handleSignup');
  }

  componentDidMount() {
    $('#signup-form').submit(this.handleSignup);
    $('#login-form').submit(this.handleLogin);

    grecaptcha.render('recaptcha', {
      sitekey: '<KEY>',
    });
  }

  handleError(err) {
    store.error = err;
    this.setState(store);
  }

  handleLogin(e) {
    e.preventDefault();

    const formData = util.convertQsToObject($('#login-form').serialize());

    axios.post('/user/login', formData)
      .then(({ data }) => {
        switch (data.code) {
          case 200:
            router.setRoute('/loadouts');
            break;
          case 400:
          case 500:
            $('#usernameEmail').select();
            this.handleError(data.message);
            break;
          default:
        }
      })
      .catch(() => {
        // TODO: Show an error message
      });
  }

  handleSignup(e) {
    e.preventDefault();

    const formData = util.convertQsToObject($('#signup-form').serialize());

    axios.post('/user', formData)
      .then(({ data }) => {
        switch (data.code) {
          case 200:
            router.setRoute('/loadouts');
            break;
          case 400:
          case 500:
            $('#username').select();
            this.handleError(data.message);
            grecaptcha.reset();
            break;
          default:
        }
      })
      .catch(() => {
        // TODO: Show an error message
      });
  }

  render() {
    return (
      <div>
        <Message text={store.error} />
        <Helmet
          // Include Recaptcha library for signups
          script={[
            { src: 'https://www.google.com/recaptcha/api.js?render=explicit' },
{'fraction_non_alphanumeric': 0.1595744680851064, 'fraction_numerical': 0.00851063829787234, 'mean_word_length': 1.89596167008898, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 16, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '908334', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1216, 'n_words': 266}