<commit_before>var async = require('async');
var _ = require('underscore');
/*
 * GET users listing.
 */
var passport = require('passport');
module.exports = function(app){
    var route = app.njax.routes.auth = {
        init:function(){

            //If Access Token Exists use it
            app.use(function(req, res, next){
                async.series([
                    function(cb){
                        //return next();
                        if(!req.cookies['access_token'] &&  req.user){
                            //Create an access token for it
                            return app.njax.api.create_token(req.user, app.njax.config.core_app, function(err, access_token){
                                if(err) return next(err);
                                res.cookie('access_token', access_token);
                                return cb();
                            });
                        }
                        return cb();
                    },
                    function(cb){
                        if(req.user && req.cookies['access_token']){
                            res.bootstrap('access_token', req.cookies['access_token']);
                        }
                        return cb();
                    },
                    /* THIS DETERMINS IF THE USER IS A SUPER ADMIN */
                    function(cb){


                        if(req.user && app.njax.config.super_admin_emails && _.contains(app.njax.config.super_admin_emails, req.user.email)){
                            res.bootstrap('is_admin', true);
                        }
                        return cb();
                    }
                ],
                function(){
                    //end async
                    return next();
                });




            });


            app.get(app.njax.config.register_url, function(req, res) {
                res.render('register', { });
            });

            app.post(
                app.njax.config.register_url,
                [
                    route.pre_register,
                    route.register,
                    route.post_register
                ]
            );


            app.post(
                app.njax.config.auth_url,
                [
                    route.pre_auth,
                    route.auth,
                    //route.post_auth
                ]
            );
            app.get(
                app.njax.config.auth_url,
                [
                    route.render_auth
                ]
            )

            app.get(
                '/logout',
                [
                    route.pre_logout,
                    route.logout,
                    route.post_logout
                ]
            );
        },
        auth:function(req, res, next){
            passport.authenticate('local', {
                successRedirect: '/',
                failureRedirect: '/login?error',
                failureFlash: true
            })
        },
        render_auth:function(req, res, next){
            res.render('auth');
        },
        pre_auth:function(req, res, next){<commit_msg>api auth stuff<commit_after>var async = require('async');
var _ = require('underscore');
/*
 * GET users listing.
 */
var passport = require('passport');
module.exports = function(app){
    var route = app.njax.routes.auth = {
        init:function(){

            //If Access Token Exists use it
            app.use(function(req, res, next){
                async.series([
                    function(cb){
                        //return next();
                        if(!req.cookies['access_token'] &&  req.user){
                            //Create an access token for it
                            return app.njax.api.create_token(req.user, app.njax.config.core_app, function(err, access_token){
                                if(err) return next(err);
                                res.cookie('access_token', access_token);
                                return cb();
                            });
                        }
                        return cb();
                    },
                    function(cb){
                        if(req.user && req.cookies['access_token']){
                            res.bootstrap('access_token', req.cookies['access_token']);
                        }
                        return cb();
                    },
                    /* THIS DETERMINS IF THE USER IS A SUPER ADMIN */
                    function(cb){


                        if(req.user && app.njax.config.super_admin_emails && _.contains(app.njax.config.super_admin_emails, req.user.email)){
                            res.bootstrap('is_admin', true);
                        }
                        return cb();
                    }
                ],
                function(){
                    //end async
                    return next();
                });




            });


            app.get(app.njax.config.register_url, function(req, res) {
                res.render('register', { });
            });

            app.post(
                app.njax.config.register_url,
                [
                    route.pre_register,
                    route.register,
                    route.post_register
                ]
            );


            app.post(
                app.njax.config.auth_url,
                [
                    route.pre_auth,
                    route.auth,
                    //route.post_auth
                ]
            );
            app.get(
                app.njax.config.auth_url,
                [
                    route.render_auth
                ]
            )

            app.get(
                '/logout',
                [
                    route.pre_logout,
                    route.logout,
                    route.post_logout
                ]
            );
        },
        auth://function(req, res, next){
            passport.authenticate('local', {
                successRedirect: '/',
                failureRedirect: '/login?error',
                failureFlash: true
            }),//;
        //},
        render_auth:function(req, res, next){
            res.render('auth');
        },
        pre_auth:function(req, res, next){
{'fraction_non_alphanumeric': 0.10577988915281077, 'fraction_numerical': 0.0, 'mean_word_length': 0.8625774107932763, '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': '1024407', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1431, 'n_words': 241}