<commit_before>
const mongoose = require('mongoose');
const Users = mongoose.model('Users');
const passport = require('passport');

exports.oauthCallback = function(strategy) {
  return function(req, res, next) {
    passport.authenticate(strategy, function(err, user, redirectURL) {
      if (err || !user) {
        console.log(err, user);
        return res.redirect('/');
      }
      req.login(user, function(err) {
        if (err) {
          return res.redirect('/');
        }
        return res.redirect(redirectURL || '/');
      });
    })(req, res, next);
  };
};

exports.saveOAuthUserProfile = function(req, profile, done) {
  // Find user with provider and ID

  var provider = profile.provider;
  var IDField = 'providers.'+ provider + '.' + profile.providerIdentifierField;
  var data = profile.providerData;

  var query = {};
  query[IDField] = data[profile.providerIdentifierField];

  Users.findOne(query, (err, user) => {
    if(err) {
      return done(err);
    } else {
      if(!user) {
        Users.findOne({'email': profile.email}, (err, user) => {
          if(err) {
            return done(err);
          } else {
            function setProvider(uuser) {

              if(!uuser.providers) {
                uuser.providers = {};
              }
              uuser.providers[provider] = data;
              uuser.save(err => {
                return done(err, user);
              });
            }
            if(!user) {
              var user = new Users({
                email: profile.email,
                providers: {}
              });
              console.log("Created new user");
              setProvider(user);

            } else { // Found user with email but no provider
              console.log("Applied provider "+provider+" to existing user");
              setProvider(user);
            }
          }
        });
      } else { // Found user with provider
        console.log("User found with provider "+ provider);
        console.log(user);
        done(err, user);
      }
    }
  });
}
<commit_msg>Remove user log when sign in<commit_after>
const mongoose = require('mongoose');
const Users = mongoose.model('Users');
const passport = require('passport');

exports.oauthCallback = function(strategy) {
  return function(req, res, next) {
    passport.authenticate(strategy, function(err, user, redirectURL) {
      if (err || !user) {
        console.log(err, user);
        return res.redirect('/');
      }
      req.login(user, function(err) {
        if (err) {
          return res.redirect('/');
        }
        return res.redirect(redirectURL || '/');
      });
    })(req, res, next);
  };
};

exports.saveOAuthUserProfile = function(req, profile, done) {
  // Find user with provider and ID

  var provider = profile.provider;
  var IDField = 'providers.'+ provider + '.' + profile.providerIdentifierField;
  var data = profile.providerData;

  var query = {};
  query[IDField] = data[profile.providerIdentifierField];

  Users.findOne(query, (err, user) => {
    if(err) {
      return done(err);
    } else {
      if(!user) {
        Users.findOne({'email': profile.email}, (err, user) => {
          if(err) {
            return done(err);
          } else {
            function setProvider(uuser) {

              if(!uuser.providers) {
                uuser.providers = {};
              }
              uuser.providers[provider] = data;
              uuser.save(err => {
                return done(err, user);
              });
            }
            if(!user) {
              var user = new Users({
                email: profile.email,
                providers: {}
              });
              console.log("Created new user");
              setProvider(user);

            } else { // Found user with email but no provider
              console.log("Applied provider "+provider+" to existing user");
              setProvider(user);
            }
          }
        });
      } else { // Found user with provider
        done(err, user);
      }
    }
  });
}

{'fraction_non_alphanumeric': 0.13782051282051283, 'fraction_numerical': 0.0, 'mean_word_length': 1.78067169294037, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3807365', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1118, 'n_words': 257}