daily pastebin goal
50%
SHARE
TWEET

Untitled

a guest Jan 28th, 2016 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var errorsArr= [];
  2.  
  3. var username = new Promise(function(resolve,reject){
  4.     User.findOne({ "username": req.body.username },function(err,user){
  5.         if(err)
  6.             reject(err);
  7.  
  8.         if(user) {
  9.             resolve(1);
  10.         }else{
  11.             resolve(0);
  12.         }
  13.     });
  14. });
  15. username.then(function(data){
  16.     if( data == 1 )
  17.         errorsArr.push({"msg": "Username already been taken."});
  18. }).catch(function(err){
  19.     console.log(err);
  20. });
  21.  
  22. var email = new Promise(function(resolve,reject){
  23.     User.findOne({ "email": req.body.email },function(err,user){
  24.         if(err)
  25.             reject(err);
  26.  
  27.         if(user) {
  28.             resolve(1);
  29.         }else{
  30.             resolve(0);
  31.         }
  32.     });
  33. });
  34. email.then(function(data){
  35.     if( data == 1 )
  36.         errorsArr.push({"msg": "email already been taken."});
  37. }).catch(function(err){
  38.     console.log(err);
  39. });
  40.  
  41. if(errorsArr.length >0)
  42. {
  43.     req.session.error = errorsArr;
  44.     return  res.redirect('/auth/Registration');
  45. }
  46. else {
  47.     var newUser = new User();
  48.     newUser.username = req.body.username;
  49.     newUser.password = req.body.password;
  50.     newUser.sex = req.body.sex;
  51.     newUser.email = req.body.email;
  52.     newUser.phoneNumber = req.body.phoneNumber;
  53.     newUser.age = req.body.age;
  54.     newUser.designation = req.body.designation;
  55.     newUser.timing = req.body.timing;
  56.     var CurrentDate = moment.tz(new Date(req.body.joiningDate), "Asia/Karachi").unix();
  57.     newUser.joiningDate = CurrentDate;
  58.     newUser.save(function (err, user) {
  59.         if (!err)
  60.             return res.redirect('/auth/Login');
  61.     });
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top