<commit_before>var passport = require("passport");

module.exports = function(_request, _response, _next) {
    if (_request.isAuthenticated()) {
    	var user = _request.user.toJSON();
        _response
            ._R
            ._DATA("user", user)
            ._SUCCESS("Welcome back " + user.username + "!")
            ._SEND();
        return;
    }
    _request.body = _request.query; //Makes sure that passport can read credentials

    passport.authenticate("local-login", function(err, user, info) {
        if (!err) {
            _request.logIn(user, function(err) {
                if (!err) {
                    if (_request.body.remember_me == "true") {
                        _request.session.cookie.maxAge = 21 * 24 * 60 * 60 * 1000;
                    }
                    _response
                        ._R
                        ._DATA("user", user.toJSON())
                        ._SUCCESS("Welcome back " + user.username + "!")
                        ._SEND();
                } else {
                    _response
                        ._R
                        ._ERROR(err)
                        ._STATUS(400)
                        ._SEND();
                }
            });
        } else {
            _response<commit_msg>Extended user to collect thread comment references when signing in<commit_after>var passport = require("passport"),
    SCHEMA_THREAD_COMMENT = require(process.env.APP_SCHEMA_THREAD_COMMENT);

module.exports = function(_request, _response, _next) {
    if (_request.isAuthenticated()) {
        var user = _request.user.toJSON();
        _response
            ._R
            ._DATA("user", user)
            ._SUCCESS("Welcome back " + user.username + "!")
        SCHEMA_THREAD_COMMENT.find({
                users: _request.user._id
            }, "reference is_thread_comment")
            .then(function(result) {
                console.log(result);
                _response
                    ._R
                    ._DATA("comments", result);
            })
            .catch(function(err) {
                _response
                    ._R
                    ._ERROR("Failed to collect comments")
                    ._DATA("comments", []);
                console.trace(err);
            })
            .finally(function() {
                _response
                    ._R
                    ._SEND();
            });
        return;
    }
    _request.body = _request.query; //Makes sure that passport can read credentials

    passport.authenticate("local-login", function(err, user, info) {
        if (!err) {
            _request.logIn(user, function(err) {
                if (!err) {
                    if (_request.body.remember_me == "true") {
                        _request.session.cookie.maxAge = 21 * 24 * 60 * 60 * 1000;
                    }
                    _response
                        ._R
                        ._DATA("user", user.toJSON())
                        ._SUCCESS("Welcome back " + user.username + "!")

                    SCHEMA_THREAD_COMMENT.find({
                            users: _request.user._id
                        }, "reference is_thread_comment")
                        .then(function(result) {
                            console.log(result);
                            _response
                                ._R
                                ._DATA("comments", result);
                        })
                        .catch(function(err) {
                            _response
                                ._R
                                ._ERROR("Failed to collect comments")
                                ._DATA("comments", []);
                            console.trace(err);
                        })
                        .finally(function() {
                            _response
                                ._R
                                ._SEND();
                        });
                } else {
                    _response
                        ._R
                        ._ERROR(err)
                        ._STATUS(400)
                        ._SEND();
                }
            });
        } else {
            _response
{'fraction_non_alphanumeric': 0.10115811864807374, 'fraction_numerical': 0.007090522335145356, 'mean_word_length': 0.917535115541459, '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': '4092843', 'n_tokens_mistral': 1085, 'n_tokens_neox': 937, 'n_words': 186}