SHARE
TWEET

Untitled

a guest Jun 19th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let regiseredUser = {}
  2.   User.findOne({ email: req.body.email }).then(user => {
  3.     if (user) {
  4.       return res.status(400).json({ email: "Email already exists" });
  5.     } else {
  6.       const newUser = new User({
  7.         name: req.body.name,
  8.         email: req.body.email,
  9.         password: req.body.password,
  10.         verified: req.body.verified,
  11.       });
  12.       newUser.verified = false;
  13.  
  14.       // Hash password before saving in database
  15.       bcrypt.genSalt(10, (err, salt) => {
  16.         bcrypt.hash(newUser.password, salt, (err, hash) => {
  17.           if (err) throw err;
  18.           newUser.password = hash;
  19.           newUser
  20.             .save()
  21.             .then((user) => {
  22.               regiseredUser = user;
  23.  
  24.               res.json(user)}
  25.  
  26.               )
  27.             .catch(err => console.log(err));
  28.         });
  29.       });
  30.       console.log(regiseredUser)
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