<commit_before>var LocalStrategy = require('passport-local').Strategy;
var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
var TwitterStrategy = require('passport-twitter').Strategy;
var LinkedInStrategy = require('passport-linkedin-oauth2').OAuth2Strategy;
var GitHubStrategy = require('passport-github').Strategy;

var regex = require('regex-email');
var uuid = require('node-uuid');
var nodemailer = require('nodemailer'); 
var smtpTransport = require('nodemailer-smtp-transport');


var User = require('../app/models/user.js');
var  configAuth = require('./auth');

module.exports = function(passport) {
	
	console.log("passport.js");
	passport.serializeUser(function(user, done) {
		console.log("Serialize");
		done(null, user.id);
	});

	passport.deserializeUser(function(id, done) {
		console.log("De-Serialize");
		User.findById(id, function(err, user) {
			done(err, user);
		});
	});

	passport.use('local-signup', new LocalStrategy({
			usernameField : 'email',
			passwordField : 'password',
			passReqToCallback: true	
		},
		function(req, email, password, done) {

			process.nextTick(function() {

				if(regex.test(email))
				{
					User.findOne({'local.email' : email}, function (err, user) {
						if(err){
							console.log("findOne-err");
							return done(err);
						}
						if(user){
							console.log("findOne-user");
							return done(
								null, 
								false, 
								req.flash('signupMessage', 'That email is already taken.')
							);
						}
						else{
							console.log("findOne-new-user");
							var newUser = new User();
							newUser.local.email    = email;
							newUser.local.password = <PASSWORD>(password);
							newUser.local.verified = false;
							console.log("hash generated...");
							newUser.save(function(err) {
								if (err){
								    console.log("error generated...");
								    throw err;
						        }
								console.log(uuid.v4());


								User.findOne({'local.email': email}, function(err, user) {
									var newLocalVerify = new User();
									newLocalVerify.localVerify.userId = user._id;
									var token = newLocalVerify.generateHash(uuid.v4())
									newLocalVerify.localVerify.verificationToken = token;

									/*var transporter = 
										nodemailer.createTransport(
											'smtps://<EMAIL>:/<EMAIL>'
										);*/

									var smtpConfig = {
									    host: 'smtp.gmail.com',
									    port: 465,
									    secure: true, // use SSL
									    auth: {
									        user: '<EMAIL>',
									        pass: <PASSWORD>.'
									    },
									     tls:{
    								    	rejectUnauthorized: false
    									}
									};

									var transporter = nodemailer.createTransport(smtpTransport(smtpConfig));

									transporter.verify(function(error, success) {
										if (error) {
										    console.log(error);
										} else {
										    console.log('Server is ready to take our messages');
										}
									});

										var mailOptions = {
										    from: '<EMAIL>',
										    to: '<EMAIL>',
										    subject: 'Account Activation',
										    text: 'Please click on the given link',
										    html: '<a href="127.0.0.1/verify?token="/>'
										};
										console.log('Message sent sefr');

										transporter.sendMail(mailOptions, function(error, info){
										    if(error){
										    	console.log(error);
										        return error;
										    }
										    console.log(info);	
										});


									newLocalVerify.save(function(err) {
										if(err)
											throw err;
									});
								});

			                    return done(
			                    	null,
			                    	newUser, 
			                    	req.flash('loginMessage', 'Verification Link has been sent to you.')
			                    );
							});
						}
					});
				}
				else{
					return done(
						null, 
						false, 
						req.flash('signupMessage', 'Oops!! Enter Valid Email Address')
					);<commit_msg>Update passport.js<commit_after>var LocalStrategy = require('passport-local').Strategy;
var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
var TwitterStrategy = require('passport-twitter').Strategy;
var LinkedInStrategy = require('passport-linkedin-oauth2').OAuth2Strategy;
var GitHubStrategy = require('passport-github').Strategy;

var regex = require('regex-email');
var uuid = require('node-uuid');
var nodemailer = require('nodemailer'); 
var smtpTransport = require('nodemailer-smtp-transport');


var User = require('../app/models/user.js');
var  configAuth = require('./auth');

module.exports = function(passport) {
	
	console.log("passport.js");
	passport.serializeUser(function(user, done) {
		console.log("Serialize");
		done(null, user.id);
	});

	passport.deserializeUser(function(id, done) {
		console.log("De-Serialize");
		User.findById(id, function(err, user) {
			done(err, user);
		});
	});

	passport.use('local-signup', new LocalStrategy({
			usernameField : 'email',
			passwordField : 'password',
			passReqToCallback: true	
		},
		function(req, email, password, done) {

			process.nextTick(function() {

				if(regex.test(email))
				{
					User.findOne({'local.email' : email}, function (err, user) {
						if(err){
							console.log("findOne-err");
							return done(err);
						}
						if(user){
							console.log("findOne-user");
							return done(
								null, 
								false, 
								req.flash('signupMessage', 'That email is already taken.')
							);
						}
						else{
							console.log("findOne-new-user");
							var newUser = new User();
							newUser.local.email    = email;
							newUser.local.password = <PASSWORD>);
							newUser.local.verified = false;
							console.log("hash generated...");
							newUser.save(function(err) {
								if (err){
								    console.log("error generated...");
								    throw err;
						        	}
						//console.log(uuid.v4());
					                return done(
					                   	null,
					                    	newUser, 
					                    	req.flash('loginMessage', 'Successfully Registered!')
					                    );
							});
						}
					});
				}
				else{
					return done(
						null, 
						false, 
						req.flash('signupMessage', 'Oops!! Enter Valid Email Address')
					);
{'fraction_non_alphanumeric': 0.1413662239089184, 'fraction_numerical': 0.0028462998102466793, 'mean_word_length': 2.035028790786948, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '7614812', 'n_tokens_mistral': 2775, 'n_tokens_neox': 1837, 'n_words': 343}