<commit_before>var User = require('../models/user.js');
var ID_LENGTH = 5;

module.exports = function(passport, LocalStrategy) {
	passport.serializeUser(function(user, done) {
		done(null, user.id);
	});

	// used to deserialize the user
	passport.deserializeUser(function(id, done) {
		User.findById(id, function(err, user) {
			done(err, user);
		});
	});

	passport.use('local-signup', new LocalStrategy({
		usernameField: 'email',
		passwordField: 'password',
		passReqToCallback: true // allows us to pass back the entire request to the callback
	}, function(req, email, password, done) {
		// asynchronous
		// User.findOne wont fire unless data is sent back
		process.nextTick(function() {
			req.flash("email", email);
			User.findOne({
				'email': email
			}).exec().then(function(err, user) {
				if (user) {
					return done(null, false, req.flash('error', 'That email is already registered'));
				} else {
					function randomString(length) {
						return Math.random().toString(36).substr(2, length || ID_LENGTH);
					}

					function attemptCreation(shortID) {
						User.find({shortID: shortID}).exec()
						.then(function(users) {
							if(users.length == 0) {
								var newUser = new User();
								newUser.displayname = req.body.displayname;
								newUser.password = <PASSWORD>);
								newUser.email = email;
								newUser.shortID = shortID;
								newUser.emoji = req.body.emoji;
								newUser.createdat = Date.now();
								newUser.changedat = Date.now();
<commit_msg>fixed dupe email crashing<commit_after>var User = require('../models/user.js');
var ID_LENGTH = 5;

module.exports = function(passport, LocalStrategy) {
	passport.serializeUser(function(user, done) {
		done(null, user.id);
	});

	// used to deserialize the user
	passport.deserializeUser(function(id, done) {
		User.findById(id, function(err, user) {
			done(err, user);
		});
	});

	passport.use('local-signup', new LocalStrategy({
		usernameField: 'email',
		passwordField: 'password',
		passReqToCallback: true // allows us to pass back the entire request to the callback
	}, function(req, email, password, done) {
		// asynchronous
		// User.findOne wont fire unless data is sent back
		process.nextTick(function() {
			req.flash("email", email);
			User.findOne({
				'email': email
			}).exec()
			.then(function(user) {
				if (user) {
					return done(null, false, req.flash('error', 'That email is already registered'));
				} else {
					function randomString(length) {
						return Math.random().toString(36).substr(2, length || ID_LENGTH);
					}

					function attemptCreation(shortID) {
						User.find({shortID: shortID}).exec()
						.then(function(users) {
							if(users.length == 0) {
								var newUser = new User();
								newUser.displayname = req.body.displayname;
								newUser.password = <PASSWORD>);
								newUser.email = email;
								newUser.shortID = shortID;
								newUser.emoji = req.body.emoji;
								newUser.createdat = Date.now();
								newUser.changedat = Date.now();

{'fraction_non_alphanumeric': 0.14389679126695334, 'fraction_numerical': 0.0033079722130334105, 'mean_word_length': 3.2293706293706292, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5781023', 'n_tokens_mistral': 1193, 'n_tokens_neox': 935, 'n_words': 221}