<commit_before>/**
 * AuthController
 *
 * @module      :: Controller
 * @description :: Contains logic for handling requests.
 */
var passport = require('passport');

module.exports = {
    /**
     * Login action, basically this just shows login screen.
     *
     * @param   {Request}   req Request object
     * @param   {Response}  res Response object
     */
    login: function(req, res) {
        var error = req.param("error");

        // If user is already signed in redirect to main page
        if (req.user) {
            res.redirect("/");
        }

        var fs = require('fs');
        var packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));

        res.view({
            layout: "layout_login",
            error: error,
            packageJson: packageJson
        });
    },

    /**
     * Logout action, just logout user and then redirect to root.
     *
     * @param   {Request}   req Request object
     * @param   {Response}  res Response object
     */
    logout: function(req, res) {
        req.logout();
        res.redirect("/");
    },

    /**
     * Authentication action, this uses passport local directive to
     * check if user is valid user or not.
     *
     * @param req
     * @param res
     */
    authenticate: function(req, res) {
        passport.authenticate('local', function(err, user, info) {
            if ((err) || (!user)) {
                res.redirect("/login?error=true");
                return;
            }

            req.logIn(user, function(err) {
                if (err) {
                    res.view({
                        layout: "layout_login"
                    });
                } else {
                    res.redirect("/");
                }
            });
        })(req, res);
    }
};<commit_msg>Send 401 status if user login attempt fails.<commit_after>/**
 * AuthController
 *
 * @module      :: Controller
 * @description :: Contains logic for handling requests.
 */
var passport = require('passport');

module.exports = {
    /**
     * Login action, basically this just shows login screen.
     *
     * @param   {Request}   req Request object
     * @param   {Response}  res Response object
     */
    login: function(req, res) {
        var error = req.param("error");

        // If user is already signed in redirect to main page
        if (req.user) {
            res.redirect("/");
        }

        var fs = require('fs');
        var packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));

        if (error) {
            res.status(401);
        }

        res.view({
            layout: "layout_login",
            error: error,
            packageJson: packageJson
        });
    },

    /**
     * Logout action, just logout user and then redirect to root.
     *
     * @param   {Request}   req Request object
     * @param   {Response}  res Response object
     */
    logout: function(req, res) {
        req.logout();
        res.redirect("/");
    },

    /**
     * Authentication action, this uses passport local directive to
     * check if user is valid user or not.
     *
     * @param req
     * @param res
     */
    authenticate: function(req, res) {
        passport.authenticate('local', function(err, user, info) {
            if ((err) || (!user)) {

                res.redirect("/login?error=true");
                return;
            }

            req.logIn(user, function(err) {
                if (err) {
                    res.view({
                        layout: "layout_login"
                    });
                } else {
                    res.redirect("/");
                }
            });
        })(req, res);
    }
};
{'fraction_non_alphanumeric': 0.12712550607287448, 'fraction_numerical': 0.0021592442645074223, 'mean_word_length': 1.4889187374076562, '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': '4019418', 'n_tokens_mistral': 1031, 'n_tokens_neox': 981, 'n_words': 276}