<commit_before>/*jslint node: true*/

var auth = {};

auth.isAdmin = function (req, res, next) {
    'use strict';
    if (req.isAuthenticated() && req.user.auth_level === 'admin') {
        return next();
    } else {
        // req.flash("error", "Access requires admin level privileges");
        res.redirect("/login");
    }
};

auth.isEditor = function (req, res, next) {
    'use strict';
    if (req.isAuthenticated() && (req.user.auth_level === 'editor' || req.user.auth_level === 'admin')) {
        return next();
    } else {
        // req.flash("error", "Access requires editor level privileges");
        res.redirect("/login");
    }
};

auth.isViewer = function (req, res, next) {
    'use strict';
    if (req.isAuthenticated() && (req.user.auth_level === 'viewer' || req.user.auth_level === 'editor' || req.user.auth_level === 'admin')) {
        return next();
    } else {
        // req.flash("error", "Access requires viewer level privileges");
        res.redirect("/login");
    }
};

module.exports = auth;<commit_msg>add flash messages during auth redirect<commit_after>/*jslint node: true*/

var auth = {};

auth.isAdmin = function (req, res, next) {
    'use strict';
    if (req.isAuthenticated() && req.user.auth_level === 'admin') {
        return next();
    } else {
        req.flash("error", "Access requires admin level privileges.");
        res.redirect("/");
    }
};

auth.isEditor = function (req, res, next) {
    'use strict';
    if (req.isAuthenticated() && (req.user.auth_level === 'editor' || req.user.auth_level === 'admin')) {
        return next();
    } else {
        req.flash("error", "Access requires editor level privileges.");
        res.redirect("/");
    }
};

auth.isViewer = function (req, res, next) {
    'use strict';
    if (req.isAuthenticated() && (req.user.auth_level === 'viewer' || req.user.auth_level === 'editor' || req.user.auth_level === 'admin')) {
        return next();
    } else {
        req.flash("error", "Login is required.");
        res.redirect("/login");
    }
};

module.exports = auth;
{'fraction_non_alphanumeric': 0.19026974951830444, 'fraction_numerical': 0.0, 'mean_word_length': 2.79014598540146, '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': '5414880', 'n_tokens_mistral': 655, 'n_tokens_neox': 647, 'n_words': 154}