Advertisement
tareknode

signup rout

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