Advertisement
Guest User

function

a guest
Jan 21st, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. async function registerForm(req, res) {
  2.     await User.findOne({
  3.         where: {
  4.             username: req.body.username
  5.         }
  6.     }).then(async function(user) {
  7.         res.status(401).send("Username already exists.");
  8.     }).catch(function() {
  9.         /* create user */
  10.         if (req.body.password !== req.body.confirmPassword) {
  11.             res.status(401).send("Passwords do not match.");
  12.         }
  13.  
  14.         if (req.body.username == "" || req.body.password == "" || req.body.confirmPassword == "") {
  15.             res.status(401).send("One or more fields are empty.");
  16.         }
  17.  
  18.         var hashedPassword = hash.generate(req.body.password);
  19.  
  20.         User.create({
  21.             username: req.body.username,
  22.             password: hashedPassword,
  23.             avatar: "",
  24.             ip: req.ip
  25.         }).then(async function(createdUser) {
  26.             Profile.create({
  27.                 userId: createdUser.id
  28.             });
  29.  
  30.             console.log("profile created");
  31.         }).catch(function() {
  32.             res.status(500).send();
  33.         });
  34.     });
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement