<commit_before>/*jslint node: true*/
"use strict";

var nconf = require('./nconf');
var passport = require('passport'),
    DigestStrategy = require('passport-http').DigestStrategy;

exports.init = function () {
    passport.use('admin', new DigestStrategy({ qop: 'auth', realm: nconf.get('admin:realm') },
        function (username, done) {
            if (username !== nconf.get('admin:username')) { return done(null, false); }
            return done(null, username, nconf.get('admin:password'));
        }
        ));

    passport.use('pos', new DigestStrategy({ qop: 'auth', realm: nconf.get('posuser:realm') },
        function (username, done) {
            if (username !== nconf.get('posuser:username')) { return done(null, false); }
            return done(null, username, nconf.get('posuser:password'));
        }
        ));

    return passport.initialize();
};

exports.authAdmin = function (req, res, next) {
    if (nconf.get('admin:authenticate')) {
        passport.authenticate('admin', {session: false})(req, res, next);
    } else {
        next();
    }
};

exports.authPos = function (req, res, next) {
    if (nconf.get('posuser:authenticate')) {
        passport.authenticate('pos', {session: false})(req, res, next);
    } else {
        next();
    }
};<commit_msg>Authentication conf was not read right.<commit_after>/*jslint node: true*/
"use strict";

var nconf = require('./nconf');
var passport = require('passport'),
    DigestStrategy = require('passport-http').DigestStrategy;

exports.init = function () {
    passport.use('admin', new DigestStrategy({ qop: 'auth', realm: nconf.get('admin:realm') },
        function (username, done) {
            if (username !== nconf.get('admin:username')) { return done(null, false); }
            return done(null, username, nconf.get('admin:password'));
        }
        ));

    passport.use('pos', new DigestStrategy({ qop: 'auth', realm: nconf.get('posuser:realm') },
        function (username, done) {
            if (username !== nconf.get('posuser:username')) { return done(null, false); }
            return done(null, username, nconf.get('posuser:password'));
        }
        ));

    return passport.initialize();
};

exports.authAdmin = function (req, res, next) {
    if (nconf.get('admin:authenticate') === 'true') {
        passport.authenticate('admin', {session: false})(req, res, next);
    } else {
        next();
    }
};

exports.authPos = function (req, res, next) {
    if (nconf.get('posuser:authenticate') === 'true') {
        passport.authenticate('pos', {session: false})(req, res, next);
    } else {
        next();
    }
};
{'fraction_non_alphanumeric': 0.18019726858877086, 'fraction_numerical': 0.0, 'mean_word_length': 3.1138845553822154, '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': '4284417', 'n_tokens_mistral': 818, 'n_tokens_neox': 797, 'n_words': 177}