<commit_before>// Error codes & their corresponding message
var NOTOKEN = 'Could not generate a token';
var moment = require('moment');
var format = require('url').format;
var parse = require('body-parser').urlencoded({extended:false});
var Express = require('express');
var User = require('user');
var Email = require('email');
var config = require('config');

var client = require('client');
var Brute = require('express-brute');
var RedisStore = require('express-brute-redis');

var store = new RedisStore({
    client: client,
    prefix: 'brute:'
});

var limiter = new Brute(store, {
  freeRetries: 200, // max # of access to log in pages per day
  failCallback: onLimit,
});

var login = Express.Router();
var form = login.route('/');

form.all(limiter.prevent);

form.get(checkToken, function(req, res){
  res.render('log-in-email');
});

form.post(parse, checkEmail, checkReset, checkPassword);

form.all(errorHandler);

function onLimit (req, res, next, until) {
  res.status(429).send('Log in rate limit hit. Please wait ' + moment(until).toNow(true) + ' before retrying.');
}

function checkToken (req, res, next) {

  var token = req.query && req.query.token;
  var then = (req.query && req.query.then) || '/';

  if (!token) return next();

  User.checkAccessToken(token, function(err, uid){

    if (err || !uid) return next(new LogInError('BADTOKEN'));

    User.getById(uid, function(err, user){

      if (err || !user) return next(new LogInError('NOUSER'));

      User.generateAccessToken(uid, function(err, token){
<commit_msg>fix log in url bug<commit_after>// Error codes & their corresponding message
var NOTOKEN = 'Could not generate a token';
var moment = require('moment');
var format = require('url').format;
var parse = require('body-parser').urlencoded({extended:false});
var Express = require('express');
var User = require('user');
var Email = require('email');
var config = require('config');

var client = require('client');
var Brute = require('express-brute');
var RedisStore = require('express-brute-redis');

var store = new RedisStore({
    client: client,
    prefix: 'brute:'
});

var limiter = new Brute(store, {
  freeRetries: 200, // max # of access to log in pages per day
  failCallback: onLimit,
});

var login = Express.Router();
var form = login.route('/');

form.all(limiter.prevent);

form.get(checkToken, function(req, res){
  res.render('log-in-email');
});

form.post(parse, checkEmail, checkReset, checkPassword);

form.all(errorHandler);

function onLimit (req, res, next, until) {
  res.status(429).send('Log in rate limit hit. Please wait ' + moment(until).toNow(true) + ' before retrying.');
}

function checkToken (req, res, next) {

  var token = req.query && req.query.token;
  var then = (req.query && decodeURIComponent(req.query.then)) || '/';

  if (!token) return next();

  User.checkAccessToken(token, function(err, uid){

    if (err || !uid) return next(new LogInError('BADTOKEN'));

    User.getById(uid, function(err, user){

      if (err || !user) return next(new LogInError('NOUSER'));

      User.generateAccessToken(uid, function(err, token){

{'fraction_non_alphanumeric': 0.16597244472925343, 'fraction_numerical': 0.003844921499519385, 'mean_word_length': 4.686703096539162, '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': '3678694', 'n_tokens_mistral': 995, 'n_tokens_neox': 976, 'n_words': 280}