<commit_before>var User          = require('../../api/models/user');
var jwt           = require('jsonwebtoken');
var configuration = require('../config/configuration');

module.exports = {

  /**
  * Check if a token is pass in the request
  * If 'OK' information's token go in the request object
  * You can the see then in your routes with
  *
  * ==> user_id  -> req.tokenInfos.id
  * ==> username -> req.tokenInfos.username
  *
  * Render error if invalid or missing token
  */
  auth: function(req, res, next) {

    var token = req.body.token || req.param('token') || req.headers['x-access-token'];
    if (!token)
      return res.status(401).send({status: 401, message: 'Unauthorized'});
    else {
      // Verify the token
      jwt.verify(token, configuration.secretKey, function(err, decoded) {
        if (err)
          return res.status(401).send({status: 401, message: 'Unauthorized'});
        else {
          // Token decrypt save in the request
          req.tokenInfos = decoded;
          // Save informations about the user in the requet object
          User.findOne({ _id: decoded.id }, function(err, user) {
            if (err) throw err;
            if (user) {
              req.user = user;
              next();
            }
            else
              return res.status(401).send({status: 401, message: 'Unauthorized'});
          });
        }
      });
    }
  },

  /**
  * Generate a token for the future request
  * Your user send his credentials
  *
  * ==> username
  * ==> password
  *
  * If match it will generate a new token (JWT) with informations about the user
  * Render error if invalid or missing credentials
  */
  generateAuth: function(req, res, next) {

    // Check credentials in the request
    if (!req.body.username || !req.body.password)<commit_msg>remove password<commit_after>var User          = require('../../api/models/user');
var jwt           = require('jsonwebtoken');
var configuration = require('../config/configuration');

module.exports = {

  /**
  * Check if a token is pass in the request
  * If 'OK' information's token go in the request object
  * You can the see then in your routes with
  *
  * ==> user_id  -> req.tokenInfos.id
  * ==> username -> req.tokenInfos.username
  *
  * Render error if invalid or missing token
  */
  auth: function(req, res, next) {

    var token = req.body.token || req.param('token') || req.headers['x-access-token'];
    if (!token)
      return res.status(401).send({status: 401, message: 'Unauthorized'});
    else {
      // Verify the token
      jwt.verify(token, configuration.secretKey, function(err, decoded) {
        if (err)
          return res.status(401).send({status: 401, message: 'Unauthorized'});
        else {
          // Token decrypt save in the request
          req.tokenInfos = decoded;
          // Save informations about the user in the request object
          User.findOne({ _id: decoded.id }).select('-password').exec(function(err, user) {
            if (err) throw err;
            if (user) {
              req.user = user;
              next();
            }
            else
              return res.status(401).send({status: 401, message: 'Unauthorized'});
          });
        }
      });
    }
  },

  /**
  * Generate a token for the future request
  * Your user send his credentials
  *
  * ==> username
  * ==> password
  *
  * If match it will generate a new token (JWT) with informations about the user
  * Render error if invalid or missing credentials
  */
  generateAuth: function(req, res, next) {

    // Check credentials in the request
    if (!req.body.username || !req.body.password)
{'fraction_non_alphanumeric': 0.1291735084838533, 'fraction_numerical': 0.009852216748768473, 'mean_word_length': 2.228798586572438, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4910997', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1040, 'n_words': 328}