Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- router.post("/signup", signupValidation, passport.authenticate("local.signup", {
- successRedirect: "/buyer/profile",
- failureRedirect: "/buyer/signup",
- failureFlash: true
- }));
- // start validation for signup form
- function signupValidation(req, res, next) {
- "use strict";
- // grabe the form values
- var username = req.body.username;
- var email = req.body.email;
- var number = req.body.number;
- var password = req.body.password;
- var confirmpassword = req.body.confirmpassword;
- // check of the profile picture
- if (req.files && req.files.profileimage) {
- var profileImageOriginalNmae = req.files.profileimage.originalname;
- var profileImageName = req.files.profileimage.name;
- var profileImagePath = req.files.profileimage.path;
- var profileImageExt = req.files.profileimage.extention;
- var profileImageSize = req.files.profileimage.size;
- var profileImageMimeType = req.files.profileimage.mimetype;
- } else {
- var profileImageNmae = "noimage.png";
- }
- // check fields with validator
- req.checkBody("username", "username is required").notEmpty();
- req.checkBody("email", "email is required").notEmpty();
- req.checkBody("email", "invalid email").isEmail();
- req.checkBody("password", "password is required").notEmpty();
- req.checkBody("password", "password should containes 5 character at least").isLength({min: 5});
- req.checkBody("password", "password should contains at least one number").matches(/^(?=.*\d)(?=.*[a-z])[0-9a-z]{5,}$/, "i");
- req.checkBody("confirmpassword", "password sies not match").equals(req.body.password);
- req.checkBody("profileimage", "profile image is required").notEmpty();
- // errors
- var errors = req.validationErrors();
- if (errors) {
- res.render("users/buyers/signup", {
- errors: errors,
- username: username,
- email: email,
- password: password,
- confirmpassword: confirmpassword
- });
- } else {
- return next();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement