<commit_before>module.exports = function(app, p***REMOVED***port, provisioning, googleStrategy) {

  var GoogleStrategy = require('p***REMOVED***port-google-oauth').OAuth2Strategy
    , Token = require('../models/token')
    , User = require('../models/user')
    , Device = require('../models/device')
    , Role = require('../models/role')
    , api = require('../api')
    , config = require('../config.json');

  console.log('configuring google authentication');

  function authenticate(req, res, next) {
    p***REMOVED***port.authenticate('google', function(err, user, info) {
      if (err) return next(err);
      info = info || {};

      if (!user) {
        return res.render('authentication', { host: req.getRoot(), success: false, login: {errorMessage: info.message} });
      }

      req.user = user;
      next();
    })(req, res, next);
  }

  function provisionDevice(req, res, next) {
    var state = JSON.parse(req.query.state);

    provisioning.provision.check(provisioning.strategy, {uid: state.uid}, function(err, device) {
      if (err) return next(err);

      var device = {
        uid: state.uid,
        userId: req.user._id
      }

      if (provisioning.strategy === 'uid' && (!device || !device.registered)) {
        Device.createDevice(device, function(err, newDevice) {
          var msg = 'Your device needs to be registered, please contact your MAGE administrator.';
          return res.render('authentication', { host: req.getRoot(), success: false, login: {user: req.user, device: newDevice, errorMessage: msg}});
        });<commit_msg>Don't override new device we are checking<commit_after>module.exports = function(app, p***REMOVED***port, provisioning, googleStrategy) {

  var GoogleStrategy = require('p***REMOVED***port-google-oauth').OAuth2Strategy
    , Token = require('../models/token')
    , User = require('../models/user')
    , Device = require('../models/device')
    , Role = require('../models/role')
    , api = require('../api')
    , config = require('../config.json');

  console.log('configuring google authentication');

  function authenticate(req, res, next) {
    p***REMOVED***port.authenticate('google', function(err, user, info) {
      if (err) return next(err);
      info = info || {};

      if (!user) {
        return res.render('authentication', { host: req.getRoot(), success: false, login: {errorMessage: info.message} });
      }

      req.user = user;
      next();
    })(req, res, next);
  }

  function provisionDevice(req, res, next) {
    var state = JSON.parse(req.query.state);

    provisioning.provision.check(provisioning.strategy, {uid: state.uid}, function(err, device) {
      if (err) return next(err);

      if (provisioning.strategy === 'uid' && (!device || !device.registered)) {
        Device.createDevice({ uid: state.uid, userId: req.user._id }, function(err, newDevice) {
          var msg = 'Your device needs to be registered, please contact your MAGE administrator.';
          return res.render('authentication', { host: req.getRoot(), success: false, login: {user: req.user, device: newDevice, errorMessage: msg}});
        });
{'fraction_non_alphanumeric': 0.17064629099013054, 'fraction_numerical': 0.0006367398917542184, 'mean_word_length': 3.304109589041096, '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': '7115308', 'n_tokens_mistral': 946, 'n_tokens_neox': 921, 'n_words': 224}