<commit_before>koding          = require './../bongo'
{ getClientId } = require './../helpers'

module.exports = (req, res) ->

  { JUser }           = koding.models
  { password, email, tfcode } = req.body

  return res.status(400).send 'Bad request'  unless email?

  { password, redirect } = req.body

  clientId =  getClientId req, res

  if clientId

    JUser.login clientId, { username : email, password, tfcode }, (err, info) ->

      {isValid : isEmail} = JUser.validateAt 'email', email, yes

      if err?.name is 'VERIFICATION_CODE_NEEDED'
        return res.status(400).send 'TwoFactor auth Enabled'

      else if err?.message is 'Access denied!'
        return res.status(400).send 'Bad request'

      else if err and isEmail
        JUser.emailAvailable email, (err_, response) ->
          return res.status(400).send 'Bad request'  if err_

          return if response
          then res.status(200).send response
          else res.status(400).send 'Email is taken!'

        return

      unless info
        return res.status(500).send 'An error occurred'

      res.cookie 'clientId', info.replacementToken, path : '/'
      return res.status(200).send 'User is logged in!'<commit_msg>small changes on validateemamil file<commit_after>koding          = require './../bongo'
{ getClientId } = require './../helpers'

module.exports = (req, res) ->

  { JUser }           = koding.models
  { password, email, tfcode } = req.body

  return res.status(400).send 'Bad request'  unless email?

  { password, redirect } = req.body

  clientId =  getClientId req, res

  if clientId

    JUser.login clientId, { username : email, password, tfcode }, (err, info) ->

      { isValid : isEmail } = JUser.validateAt 'email', email, yes

      if err?.name is 'VERIFICATION_CODE_NEEDED'
        return res.status(400).send 'TwoFactor auth Enabled'

      else if err?.message is 'Access denied!'
        return res.status(400).send 'Bad request'

      else if err and isEmail
        JUser.emailAvailable email, (err_, response) ->

          return res.status(400).send 'Bad request'  if err_

          return if response
          then res.status(200).send response
          else res.status(400).send 'Email is taken!'

        return

      unless info
        return res.status(500).send 'An error occurred'

      res.cookie 'clientId', info.replacementToken, { path : '/' }
      return res.status(200).send 'User is logged in!'
{'fraction_non_alphanumeric': 0.11673469387755102, 'fraction_numerical': 0.019591836734693877, 'mean_word_length': 2.481534090909091, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3219087', 'n_tokens_mistral': 769, 'n_tokens_neox': 710, 'n_words': 217}