<commit_before>var conf = require('../../conf');
var url = require('url');
var log = require('../winston');

if(conf.modules.google) {
  var requiredDomain = conf.modules.google.requiredDomain;
  if(requiredDomain && !requiredDomain.push) { requiredDomain = [requiredDomain]; }

  var requiredEmail = conf.modules.google.requiredEmail;
  if(requiredEmail && !requiredEmail.push) { requiredEmail = [requiredEmail]; }

  if(!requiredEmail && !requiredDomain) {
    log.error("Config must specify either requiredEmail or requiredDomain.");
    process.exit(1);
  }
}

var checkDomain = function(auth) {
  var email = auth.google.user.email.split('@');

  for(var i = 0; i < requiredDomain.length; i++) {
    if(email.length == 2 && email[1] == requiredDomain[i]) {
      return true;
    }
  }

  log.notice("User rejected because " + email + " isn't in the domain list: " + requiredDomain.join(", "));

  return false;
};

var checkEmail = function(auth) {
  var email = auth.google.user.email
  if(requiredEmail.indexOf(email) >= 0) {
    return true;
  }

  log.notice("User rejected because " + email + "isn't in the list of allowed email addresses.");

  return false;
};

exports.setup = function(everyauth) {
  everyauth.google
    .myHostname(conf.hostname)
    .appId(conf.modules.google.appId)
    .appSecret(conf.modules.google.appSecret)
    .scope('https://www.googleapis.com/auth/userinfo.email')
    .authQueryParam({ access_type:'online', approval_prompt:'auto' })
    .findOrCreateUser( function (sess, accessToken, accessTokenExtra, googleUser) {
      return googleUser;
    })
    .handleAuthCallbackError( function (req, res) {
      var parsedUrl = url.parse(req.url, true);
      req.flash('error', 'Error authenticating with Google: ' + parsedUrl.query.error);
      res.redirectTo('/');
    })
    .convertErr( function (data) {
      if(data.data) {
        return new Error(data.data.match(/H1>(.+)<\/H1/)[1]);
      } else if(data.error && data.error.message) {
        return new Error(data.error.message, data.error);
      } else {
        return new Error(JSON.stringify(data));
      }<commit_msg>no caching as we handle several hosts with it.<commit_after>var conf = require('../../conf');
var url = require('url');
var log = require('../winston');

if(conf.modules.google) {
  var requiredDomain = conf.modules.google.requiredDomain;
  if(requiredDomain && !requiredDomain.push) { requiredDomain = [requiredDomain]; }

  var requiredEmail = conf.modules.google.requiredEmail;
  if(requiredEmail && !requiredEmail.push) { requiredEmail = [requiredEmail]; }

  if(!requiredEmail && !requiredDomain) {
    log.error("Config must specify either requiredEmail or requiredDomain.");
    process.exit(1);
  }
}

var checkDomain = function(auth) {
  var email = auth.google.user.email.split('@');

  for(var i = 0; i < requiredDomain.length; i++) {
    if(email.length == 2 && email[1] == requiredDomain[i]) {
      return true;
    }
  }

  log.notice("User rejected because " + email + " isn't in the domain list: " + requiredDomain.join(", "));

  return false;
};

var checkEmail = function(auth) {
  var email = auth.google.user.email
  if(requiredEmail.indexOf(email) >= 0) {
    return true;
  }

  log.notice("User rejected because " + email + "isn't in the list of allowed email addresses.");

  return false;
};

exports.setup = function(everyauth) {
  everyauth.google
    .alwaysDetectHostname(true)
    .myHostname(conf.hostname)
    .appId(conf.modules.google.appId)
    .appSecret(conf.modules.google.appSecret)
    .scope('https://www.googleapis.com/auth/userinfo.email')
    .authQueryParam({ access_type:'online', approval_prompt:'auto' })
    .findOrCreateUser( function (sess, accessToken, accessTokenExtra, googleUser) {
      return googleUser;
    })
    .handleAuthCallbackError( function (req, res) {
      var parsedUrl = url.parse(req.url, true);
      req.flash('error', 'Error authenticating with Google: ' + parsedUrl.query.error);
      res.redirectTo('/');
    })
    .convertErr( function (data) {
      if(data.data) {
        return new Error(data.data.match(/H1>(.+)<\/H1/)[1]);
      } else if(data.error && data.error.message) {
        return new Error(data.error.message, data.error);
      } else {
        return new Error(JSON.stringify(data));
      }
{'fraction_non_alphanumeric': 0.15466543181291967, 'fraction_numerical': 0.0037045612410280156, 'mean_word_length': 3.5283018867924527, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '5285956', 'n_tokens_mistral': 1353, 'n_tokens_neox': 1321, 'n_words': 287}