<commit_before>var createUser = require('../user/userController').create;
var passport = require('passport');
var jwt = require('jsonwebtoken');
var config = require('../../config/environment');

exports.signup = function(req, res, next) {
  createUser(req, res, next);
};

exports.login = function(req, res, next) {
  passport.authenticate('local', function(err, user, info) {
    // if theres an error throw a 500
    if (err) return res.status(500).end();

    // the user doesnt exist
    if (!user && info.message.match(/Incorrect username/)) return res.json(404, {
      message: 'User does not exist'
    });

    // invalid password
    if (!user && info.message.match(/Incorrect password/)) return res.json(404, {
      message: 'Invalid password'
    });

    // the user exists, log them in, send a jwt
    if (user) {
      // we dont need to send the user password along
      delete user.password;
      // send token and logged in user info
      res.json({
        user: user,
        token: jwt.sign(user, config.jwtTokenSecret, { expiresInMinutes: 60*5 })
      });<commit_msg>update more deprecated express methods<commit_after>var createUser = require('../user/userController').create;
var passport = require('passport');
var jwt = require('jsonwebtoken');
var config = require('../../config/environment');

exports.signup = function(req, res, next) {
  createUser(req, res, next);
};

exports.login = function(req, res, next) {
  passport.authenticate('local', function(err, user, info) {
    // if theres an error throw a 500
    if (err) return res.status(500).end();

    // the user doesnt exist
    if (!user && info.message.match(/Incorrect username/)) {
      return res.status(404).json({ message: 'User does not exist' });
    }

    // invalid password
    if (!user && info.message.match(/Incorrect password/)) {
      return res.status(404).json({ message: 'Invalid password' });
    }

    // the user exists, log them in, send a jwt
    if (user) {
      // we dont need to send the user password along
      delete user.password;
      // send token and logged in user info
      res.json({
        user: user,
        token: jwt.sign(user, config.jwtTokenSecret, { expiresInMinutes: 60*5 })
      });
{'fraction_non_alphanumeric': 0.14573088958426464, 'fraction_numerical': 0.013410818059901655, 'mean_word_length': 2.9893048128342246, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6324267', 'n_tokens_mistral': 694, 'n_tokens_neox': 656, 'n_words': 206}