<commit_before>module.exports = function(mongo) {
	if(!mongo) {
		throw 'Missing mongo';
	}

	var url = 'http://' + (process.env.NODE_ENV === 'production' ? 'kpjs.azurewebsites.net' : 'localhost:1337');
	var passport = require('passport');
	var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
	var GithubStrategy = require('passport-github').Strategy;
	var TwitterStrategy = require('passport-twitter').Strategy;
	var FacebookStrategy = require('passport-facebook').Strategy;

	passport.use(new GoogleStrategy({
			clientID: process.env.GOOGLE_CLIENT_ID,
			clientSecret: process.env.GOOGLE_CLIENT_SECRET,
			callbackURL: url + '/login/google/callback',
			state: true
		},
		authCallback(function(p) {
			return p.photos[0].value;
		})
  ));

	passport.use(new GithubStrategy({
			clientID: process.env.GITHUB_CLIENT_ID,
			clientSecret: process.env.GITHUB_CLIENT_SECRET,
			callbackURL: url + '/login/github/callback',
			state: true
		},
		authCallback(function(p) {
			return p._json.avatar_url;
		})
  ));

	passport.use(new TwitterStrategy({
			consumerKey: process.env.TWITTER_CLIENT_ID,
			consumerSecret: process.env.TWITTER_CLIENT_SECRET,
			callbackURL: url + '/login/twitter/callback',
			state: true
		},
		authCallback(function(p) {
			return p.photos[0].value;
		})
	));

	passport.use(new FacebookStrategy({
			clientID: process.env.FACEBOOK_CLIENT_ID,
			clientSecret: process.env.FACEBOOK_CLIENT_SECRET,
			callbackURL: url + '/login/facebook/callback',
			profileFields: [ 'displayName', 'photos' ],
			state: true
		},
		authCallback(function(p) {
			return p.photos[0].value;
		})
	));

	passport.serializeUser(function(user, done) {
		done(null, user);
	});

	passport.deserializeUser(function(obj, done) {
		done(null, obj);
	});

	return {
		setup: setup,
		ensureOwner: ensureOwner,
		ensureZombie: ensureRoleRequestHandlerWrapper(0),
		ensureCitizen: ensureRoleRequestHandlerWrapper(1),
		ensureRuler: ensureRoleRequestHandlerWrapper(2),
		ensureRulerOrOwner: ensureRulerOrOwner
	};

	function authCallback(avatarCallback) {
		return function(token, tokenSecret, profile, done) {
			mongo.collection('users').findOneAndUpdate({ provider: profile.provider, providerId: profile.id },
				{ $set: { name: profile.displayName }, $setOnInsert: { name: profile.displayName, role: 0 } },<commit_msg>removed unnecessary ensureOwner<commit_after>module.exports = function(mongo) {
	if(!mongo) {
		throw 'Missing mongo';
	}

	var url = 'http://' + (process.env.NODE_ENV === 'production' ? 'kpjs.azurewebsites.net' : 'localhost:1337');
	var passport = require('passport');
	var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
	var GithubStrategy = require('passport-github').Strategy;
	var TwitterStrategy = require('passport-twitter').Strategy;
	var FacebookStrategy = require('passport-facebook').Strategy;

	passport.use(new GoogleStrategy({
			clientID: process.env.GOOGLE_CLIENT_ID,
			clientSecret: process.env.GOOGLE_CLIENT_SECRET,
			callbackURL: url + '/login/google/callback',
			state: true
		},
		authCallback(function(p) {
			return p.photos[0].value;
		})
  ));

	passport.use(new GithubStrategy({
			clientID: process.env.GITHUB_CLIENT_ID,
			clientSecret: process.env.GITHUB_CLIENT_SECRET,
			callbackURL: url + '/login/github/callback',
			state: true
		},
		authCallback(function(p) {
			return p._json.avatar_url;
		})
  ));

	passport.use(new TwitterStrategy({
			consumerKey: process.env.TWITTER_CLIENT_ID,
			consumerSecret: process.env.TWITTER_CLIENT_SECRET,
			callbackURL: url + '/login/twitter/callback',
			state: true
		},
		authCallback(function(p) {
			return p.photos[0].value;
		})
	));

	passport.use(new FacebookStrategy({
			clientID: process.env.FACEBOOK_CLIENT_ID,
			clientSecret: process.env.FACEBOOK_CLIENT_SECRET,
			callbackURL: url + '/login/facebook/callback',
			profileFields: [ 'displayName', 'photos' ],
			state: true
		},
		authCallback(function(p) {
			return p.photos[0].value;
		})
	));

	passport.serializeUser(function(user, done) {
		done(null, user);
	});

	passport.deserializeUser(function(obj, done) {
		done(null, obj);
	});

	return {
		setup: setup,
		ensureZombie: ensureRoleRequestHandlerWrapper(0),
		ensureCitizen: ensureRoleRequestHandlerWrapper(1),
		ensureRuler: ensureRoleRequestHandlerWrapper(2),
		ensureRulerOrOwner: ensureRulerOrOwner
	};

	function authCallback(avatarCallback) {
		return function(token, tokenSecret, profile, done) {
			mongo.collection('users').findOneAndUpdate({ provider: profile.provider, providerId: profile.id },
				{ $set: { name: profile.displayName }, $setOnInsert: { name: profile.displayName, role: 0 } },
{'fraction_non_alphanumeric': 0.13856713856713856, 'fraction_numerical': 0.005148005148005148, 'mean_word_length': 4.985879332477535, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5310879', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1546, 'n_words': 256}