Advertisement
tareknode

user route file

Jul 19th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // post the signup form
  2. function signupValidation(req, res, next) {
  3.     "use strict";
  4.     // grabe the form values
  5.     var username = req.body.username;
  6.     var email = req.body.email;
  7.     var number = req.body.number;
  8.     var password = req.body.password;
  9.     var confirmpassword = req.body.confirmpassword;
  10.         // check fields with validator
  11.         req.checkBody("username", "username is required").notEmpty();
  12.         req.checkBody("email", "email is required").notEmpty();
  13.         req.checkBody("email", "invalid email").isEmail();
  14.         req.checkBody("password", "password is required").notEmpty();
  15.         req.checkBody("password", "password should containes 5 character at least").isLength({min: 5});
  16.         req.checkBody("password", "password should contains at least one number").matches(/^(?=.*\d)(?=.*[a-z])[0-9a-z]{5,}$/, "i");
  17.         req.checkBody("confirmpassword", "password sies not match").equals(req.body.password);
  18.         //req.checkBody("profileimage", "profile image is required").notEmpty();
  19.         // errors
  20.         var errors = req.validationErrors();
  21.         if (errors) {
  22.             res.render("users/buyers/signup", {
  23.                 errors: errors,
  24.                 username: username,
  25.                 email: email,
  26.                 password: password,
  27.                 confirmpassword: confirmpassword
  28.             });
  29.         } else {
  30.             next();
  31.         }
  32. }
  33.  
  34. router.post("/signup", signupValidation, passport.authenticate("local.signup", {
  35.         //successRedirect: "/buyer/profile",
  36.         failureRedirect: "/buyer/signup",
  37.         failureFlash: true
  38. }), function (req, res, next) {
  39.     var newUser = new Buyer({
  40.         username: req.body.username,
  41.         email: req.body.email,
  42.         password: req.body.password,
  43.         confirmpassword: req.body.confirmpassword
  44.     });
  45.     newUser.save().then(res.redirect("/buyer/profile"));
  46.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement