<commit_before>import React from 'react'
import withData from 'lib/withData'
import DefaultLayout from 'components/DefaultLayout'
import {
  Container,
  Header,
  Message
} from 'semantic-ui-react'
import { Router } from 'routes'
import PlayerLoginPasswordForm from 'components/PlayerLoginPasswordForm'
import PlayerLoginPinForm from 'components/PlayerLoginPinForm'
import ServersQuery from 'components/queries/ServersQuery'

export class LoginPage extends React.Component {
  async handleOnSubmit(e, { email, password, server, name, pin }) {
    let data

    if (email) {
      data = { email, password }
    } else {
      data = { server, name, pin }
    }

    const response = await fetch(process.env.API_HOST + '/session',
      { method: 'POST'
      , body: JSON.stringify(data)
      , headers: new Headers({ 'Content-Type': 'application/json' })
      , credentials: 'include'
      })

    if (email && response.status === 204) {
      window.location.replace('/')
    } else if ((email && response.status !== 204) || response.status !== 200) {
      const responseData = await response.json()

      throw new Error(responseData.error)
    } else {
      const responseData = await response.json()

      if (responseData.hasAccount) return window.location.replace('/')

      window.location.replace('/register')
    }

  }

  render() {
    return (
      <DefaultLayout title='Login' displayNavTitle>
        <Container style={{ marginTop: '2em' }}>
          <Header>Have an account?</Header>
          <PlayerLoginPasswordForm onSubmit={this.handleOnSubmit} />
          <Message
            info
            header='Banned?'
            content='Attempt to join the server in Minecraft, type in the pin number contained within your ban message'
          />
          <Message
            info
            header='Forgot password?'
            content='Join the server in Minecraft, type /bmpin in chat and type the generated pin number below'
          />
          <ServersQuery>
            {({ servers }) => (
              <PlayerLoginPinForm servers={servers} onSubmit={this.handleOnSubmit} />
            )}
          </ServersQuery>
        </Container>
      </DefaultLayout>
    )
  }
}

export default withData(LoginPage)<commit_msg>Redirect from login page if authenticated<commit_after>import React from 'react'
import withData from 'lib/withData'
import DefaultLayout from 'components/DefaultLayout'
import {
  Container,
  Header,
  Message,
  Loader
} from 'semantic-ui-react'
import { Router } from 'routes'
import PlayerLoginPasswordForm from 'components/PlayerLoginPasswordForm'
import PlayerLoginPinForm from 'components/PlayerLoginPinForm'
import ServersQuery from 'components/queries/ServersQuery'
import withSession from 'lib/withSession'

export class LoginPage extends React.Component {
  async handleOnSubmit(e, { email, password, server, name, pin }) {
    let data

    if (email) {
      data = { email, password }
    } else {
      data = { server, name, pin }
    }

    const response = await fetch(process.env.API_HOST + '/session',
      { method: 'POST'
      , body: JSON.stringify(data)
      , headers: new Headers({ 'Content-Type': 'application/json' })
      , credentials: 'include'
      })

    if (email && response.status === 204) {
      window.location.replace('/')
    } else if ((email && response.status !== 204) || response.status !== 200) {
      const responseData = await response.json()

      throw new Error(responseData.error)
    } else {
      const responseData = await response.json()

      if (responseData.hasAccount) return window.location.replace('/')

      window.location.replace('/register')
    }

  }

  render() {
    if (this.props.session.exists && Router.router) {
      window.location.replace('/')
      return <Loader />
    }

    return (
      <DefaultLayout title='Login' displayNavTitle>
        <Container style={{ marginTop: '2em' }}>
          <Header>Have an account?</Header>
          <PlayerLoginPasswordForm onSubmit={this.handleOnSubmit} />
          <Message
            info
            header='Banned?'
            content='Attempt to join the server in Minecraft, type in the pin number contained within your ban message'
          />
          <Message
            info
            header='Forgot password?'
            content='Join the server in Minecraft, type /bmpin in chat and type the generated pin number below'
          />
          <ServersQuery>
            {({ servers }) => (
              <PlayerLoginPinForm servers={servers} onSubmit={this.handleOnSubmit} />
            )}
          </ServersQuery>
        </Container>
      </DefaultLayout>
    )
  }
}

export default withData(withSession(LoginPage))
{'fraction_non_alphanumeric': 0.11263446530267876, 'fraction_numerical': 0.004218519299725796, 'mean_word_length': 2.6170861937452328, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 30, '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': '6667748', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1263, 'n_words': 351}