<commit_before>const express = require('express');
const router = express.Router(); // eslint-disable-line new-cap
const UserModel = require('../models/user');
const jwt = require('jsonwebtoken');

router.post('/authenticate', (req, res) => {
  UserModel.findOne({ username: req.body.username }, (err, user) => {
    if (err) {
      throw err;
    }

    if (!user) {
      res.json({
        status: 'fail',
        meta: {
          message: 'Authentication not possible - username not found',
          validation: {
            username: 'That username could not be found',
          },
        },
        data: null,
      });
    } else {
      const payload = {
        id: user.id,
        username: user.username,
        name: user.name.full,
        role: user.role,
      };

      const token = jwt.sign(payload, process.env.JWT_SECRET, {
        expiresIn: req.body.remember ? '14 days' : '1 day',
      });

      res.json({
        status: 'success',
        meta: null,
        data: null,
        token,
      });
    }<commit_msg>authenticate: using config file for jwt secret<commit_after>const express = require('express');
const router = express.Router(); // eslint-disable-line new-cap
const UserModel = require('../models/user');
const jwt = require('jsonwebtoken');
const config = require('../app/config');

// Authenticate a user
router.post('/authenticate', (req, res) => {
  UserModel.findOne({ username: req.body.username }, (err, user) => {
    if (err) {
      throw err;
    }

    if (!user) {
      res.json({
        status: 'fail',
        meta: {
          message: 'Authentication not possible - username not found',
          validation: {
            username: 'That username could not be found',
          },
        },
        data: null,
      });
    } else {
      const payload = {
        id: user.id,
        username: user.username,
        name: user.name.full,
        role: user.role,
      };

      const token = jwt.sign(payload, config.jwt.secret, {
        expiresIn: req.body.remember ? '14 days' : '1 day',
      });

      res.json({
        status: 'success',
        meta: null,
        data: null,
        token,
      });
    }
{'fraction_non_alphanumeric': 0.14735401459854014, 'fraction_numerical': 0.002737226277372263, 'mean_word_length': 1.9436241610738254, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2245839', 'n_tokens_mistral': 661, 'n_tokens_neox': 646, 'n_words': 168}