Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- passport.use('local-signup', new LocalStrategy({
- passReqToCallback : true // allows us to pass back the entire request to the callback
- },
- function(req, username, password, email, name, info, done) {
- function findOrCreateUser(){
- // find a user in Mongo with provided username
- User.findOne({ 'username' : username }, function(err, user) {
- // In case of any error, return using the done method
- if (err){
- console.log('Error in SignUp: '+err);
- return done(err);
- }
- // already exists
- if (user) {
- console.log('User already exists with username: '+username);
- return done(null, false, console.log('message','User Already Exists'));
- } else {
- // if there is no user with that email
- // create the user
- var newUser = new User();
- // set the user's local credentials
- newUser.username = username;
- newUser.password = createHash(password);
- newUser.email = email;
- newUser.name = name;
- newUser.info = info;
- // save the user
- newUser.save(function(err) {
- if (err){
- console.log('Error in Saving user: '+err);
- throw err;
- }
- console.log('User Registration succesful');
- return done(null, newUser);
- });
- }
- });
- }
- // Delay the execution of findOrCreateUser and execute the method
- // in the next tick of the event loop
- process.nextTick(findOrCreateUser);
- }));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement