<commit_before>/*
    Copyright (c) 2015, SerGIS Project Contributors. All rights reserved.
    Use of this source code is governed by the MIT License, which can be found
    in the LICENSE.txt file.
*/

// node modules
var fs = require("fs"),
    path = require("path");

// required modules
var express = require("express"),
    bodyParser = require("body-parser");

// our modules
var config = require("../../config"),
    writer = require("../writer"),
    db = require("../db");


// The router for /account/
var router = module.exports = express.Router();

/**
 * Shortcut for AuthToken.checkTokenFromReq.
 *
 * @param req - The Express request object.
 * @param res - The Express response object.
 * @param {boolean} [regenerateToken=false] - Whether to regenerate the token
 *        even if we don't have to.
 * @param {Function} pageHandler - Function to call (if successful) with:
 *        the Express request, the Express response, the auth token
 */
function checkToken(req, res, regenerateToken, pageHandler) {
    if (typeof regenerateToken == "function") {
        // It's actually the callback!
        pageHandler = regenerateToken;
        regenerateToken = false;
    }
    db.models.AuthToken.checkTokenFromReq(req, !!regenerateToken).then(function (authToken) {
        // Set the new token
        res.cookie("t", authToken.token, {signed: true});
        // And, continue on our ways
        pageHandler(req, res, authToken);
    }, function (err) {
        // AHHHHHHHHHHHHHHHHHHH!!!
        console.error("Error checking auth token: ", err);
        writer.writeError(res, 500);
    });
}

// Set up body parser for POST data
router.use(bodyParser.urlencoded());<commit_msg>Fixed deprecation warning<commit_after>/*
    Copyright (c) 2015, SerGIS Project Contributors. All rights reserved.
    Use of this source code is governed by the MIT License, which can be found
    in the LICENSE.txt file.
*/

// node modules
var fs = require("fs"),
    path = require("path");

// required modules
var express = require("express"),
    bodyParser = require("body-parser");

// our modules
var config = require("../../config"),
    writer = require("../writer"),
    db = require("../db");


// The router for /account/
var router = module.exports = express.Router();

/**
 * Shortcut for AuthToken.checkTokenFromReq.
 *
 * @param req - The Express request object.
 * @param res - The Express response object.
 * @param {boolean} [regenerateToken=false] - Whether to regenerate the token
 *        even if we don't have to.
 * @param {Function} pageHandler - Function to call (if successful) with:
 *        the Express request, the Express response, the auth token
 */
function checkToken(req, res, regenerateToken, pageHandler) {
    if (typeof regenerateToken == "function") {
        // It's actually the callback!
        pageHandler = regenerateToken;
        regenerateToken = false;
    }
    db.models.AuthToken.checkTokenFromReq(req, !!regenerateToken).then(function (authToken) {
        // Set the new token
        res.cookie("t", authToken.token, {signed: true});
        // And, continue on our ways
        pageHandler(req, res, authToken);
    }, function (err) {
        // AHHHHHHHHHHHHHHHHHHH!!!
        console.error("Error checking auth token: ", err);
        writer.writeError(res, 500);
    });
}

// Set up body parser for POST data
router.use(bodyParser.urlencoded({
    extended: true
}));
{'fraction_non_alphanumeric': 0.12834691501746218, 'fraction_numerical': 0.004074505238649592, 'mean_word_length': 2.9965116279069766, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '2748840', 'n_tokens_mistral': 979, 'n_tokens_neox': 949, 'n_words': 325}