<commit_before>/** 
 * Thank you to jaredhanson/passport-local
 * https://github.com/jaredhanson/passport-local
 *
 * and jaredhanson/oauth2orize
 * https://github.com/jaredhanson/oauth2orize
 */

'use strict';

var passport = require('passport'),
    LocalStrategy = require('passport-local').Strategy,
    utils = require('../lib/utils'),
    // jaredhanson/oauth2orize
    BasicStrategy = require('passport-http').BasicStrategy,
    ClientPasswordStrategy = require('passport-oauth2-client-password').Strategy,
    BearerStrategy = require('passport-http-bearer').Strategy,
    ClientJwtBearerStrategy = require('passport-oauth2-jwt-bearer').Strategy,
    geboSchema = require('../schemata/gebo'),
    winston = require('winston');

module.exports = function(email) {

    var logger = new (winston.Logger)({ transports: [ new (winston.transports.Console)({ colorize: true }) ] });

    // Turn the email into a mongo-friend database name
    var dbName = utils.ensureDbName(email);

//    var db = require('../schemata/gebo')(dbName);

    /**
     * LocalStrategy
     *
     * This strategy is used to authenticate an agent's email and password.
     * Any time a request is made to authorize an application, we must ensure that
     * a user is logged in before asking him to approve the request.
     *
     * @param string
     * @param string
     * @param function
     */
    var _localStrategy = function(email, password, done) {
        console.log('_localStrategy');
        var db = new geboSchema(dbName);
        db.registrantModel.findOne({ email: email }, function(err, agent) {
            if (err) {
              return done(err);
            }
            if (!agent) {
              return done(null, false, { message: 'Invalid email or password' });
            }
            agent.comparePassword(password, function(err, isMatch) {
                db.connection.db.close();
                if (err) {
                  return done(err);
                }
                if(isMatch) {
                  return done(null, agent);
                }
                else {<commit_msg>Adopt cluster dependency and improve logging<commit_after>/** 
 * Thank you to jaredhanson/passport-local
 * https://github.com/jaredhanson/passport-local
 *
 * and jaredhanson/oauth2orize
 * https://github.com/jaredhanson/oauth2orize
 */

'use strict';

var passport = require('passport'),
    LocalStrategy = require('passport-local').Strategy,
    utils = require('../lib/utils'),
    // jaredhanson/oauth2orize
    BasicStrategy = require('passport-http').BasicStrategy,
    ClientPasswordStrategy = require('passport-oauth2-client-password').Strategy,
    BearerStrategy = require('passport-http-bearer').Strategy,
    ClientJwtBearerStrategy = require('passport-oauth2-jwt-bearer').Strategy,
    geboSchema = require('../schemata/gebo'),
    cluster = require('cluster'),
    winston = require('winston');

module.exports = function(email) {

    var logger = new (winston.Logger)({ transports: [ new (winston.transports.Console)({ colorize: true }) ] });

    // Turn the email into a mongo-friend database name
    var dbName = utils.ensureDbName(email);

    /**
     * LocalStrategy
     *
     * This strategy is used to authenticate an agent's email and password.
     * Any time a request is made to authorize an application, we must ensure that
     * a user is logged in before asking him to approve the request.
     *
     * @param string
     * @param string
     * @param function
     */
    var _localStrategy = function(email, password, done) {
        if (cluster.worker) {
          logger.info('_localStrategy. Worker', cluster.worker.id, 'attempting authentication');
        }

        var db = new geboSchema(dbName);
        db.registrantModel.findOne({ email: email }, function(err, agent) {
            if (err) {
              return done(err);
            }
            if (!agent) {
              return done(null, false, { message: 'Invalid email or password' });
            }
            agent.comparePassword(password, function(err, isMatch) {
                db.connection.db.close();
                if (err) {
                  return done(err);
                }
                if(isMatch) {
                  return done(null, agent);
                }
                else {
{'fraction_non_alphanumeric': 0.1206378553270164, 'fraction_numerical': 0.0023110700254217703, 'mean_word_length': 2.357641582622188, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '294155', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1202, 'n_words': 294}