<commit_before>'use strict'
const winston           = require('winston')
const chalk             = require('chalk')
const jwt               = require('jsonwebtoken')

const User              = require('../../../models/User')
const sessionSecret       = require('../../../config').sessionSecret

module.exports = function( req, res ) {
  if( !req.body.email ) return res.send( { success: false, message:'Do not fuck with us'} )
  if( !req.body.password ) return res.send( { success: false, message:'Do not fuck with us'} )

  User.findOne( { 'email': req.body.email } )
  .then( myUser => {
    if( !myUser ) return res.send( { success: false, message:'Do not fuck with us'} )
    myUser.validatePassword( req.body.password, myUser.password, match => {
      if( match === false ) return res.send( { success: false, message: 'Invalid password.'} )
      myUser.logins.push( { date: Date.now() } )
      myUser.save()
      let profile = {
        _id: myUser._id,
        name: myUser.name,
      }
      let token = 'JWT ' + jwt.sign( profile, sessionSecret, { expiresIn: '24h' } )
      res.send( { success: true, token: token, user: profile } )
    })
  })
  .catch( err => {
    res.send( { success: false, message: err } )
  })
}<commit_msg>returning apitoken as well on login<commit_after>'use strict'
const winston           = require('winston')
const chalk             = require('chalk')
const jwt               = require('jsonwebtoken')

const User              = require('../../../models/User')
const sessionSecret       = require('../../../config').sessionSecret

module.exports = function( req, res ) {
  if( !req.body.email ) return res.send( { success: false, message:'Do not fuck with us'} )
  if( !req.body.password ) return res.send( { success: false, message:'Do not fuck with us'} )

  User.findOne( { 'email': req.body.email } )
  .then( myUser => {
    if( !myUser ) return res.send( { success: false, message:'Do not fuck with us'} )
    myUser.validatePassword( req.body.password, myUser.password, match => {
      if( match === false ) return res.send( { success: false, message: 'Invalid password.'} )
      myUser.logins.push( { date: Date.now() } )
      myUser.save()
      let profile = {
        _id: myUser._id,
        apitoken: myUser.apitoken,
        name: myUser.name,
      }
      let token = 'JWT ' + jwt.sign( profile, sessionSecret, { expiresIn: '24h' } )
      res.send( { success: true, token: token, user: profile } )
    })
  })
  .catch( err => {
    res.send( { success: false, message: err } )
  })
}
{'fraction_non_alphanumeric': 0.1629367883784845, 'fraction_numerical': 0.0015704750687082843, 'mean_word_length': 2.5536959553695957, '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': 6, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4417749', 'n_tokens_mistral': 806, 'n_tokens_neox': 794, 'n_words': 217}