Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // post the 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 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 {
- next();
- }
- }
- router.post("/signup", signupValidation, passport.authenticate("local.signup", {
- //successRedirect: "/buyer/profile",
- failureRedirect: "/buyer/signup",
- failureFlash: true
- }), function (req, res, next) {
- var newUser = new Buyer({
- username: req.body.username,
- email: req.body.email,
- password: req.body.password,
- confirmpassword: req.body.confirmpassword
- });
- newUser.save().then(res.redirect("/buyer/profile"));
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement