Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- passport.use('local-register', new LocalStrategy(
- {usernameField: 'user_name', passwordField: 'password', passReqToCallback: true},
- function(req, name, password, done){ // done is a callback
- // asynchronous, waits for everything to be completed before executing
- console.log(req.body.email + " " + name + " " + password + " ");
- process.nextTick(function(){
- // search database for email that matches the registration email
- User.findOne({'local.email': req.body.email}, function(err, user){ // check database for email given in register
- if(err) // if there is an error return to callback err
- return done(err);
- if(user){ // if there is an email match, return to register and display flash message
- return done(null, false, req.flash('registerMessage', 'That email is already taken'));
- } else { // otherwise create a new user
- var newUser = new User();
- newUser.local.username = name;
- newUser.local.password = password;
- newUser.local.email = req.body.email;
- newUser.save(function(err){
- if(err)
- throw err;
- return done(null, newUser); // return done with no error and the newUser
- });
- }
- })
- });
- }));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement