Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exports.validateRegister = (req, res, next) => {
- const sessionErros = [];
- req.sanitizeBody('name');
- req.checkBody('name', 'You must supply a name!').notEmpty();
- req.checkBody('email', 'That Email is not valid!').isEmail();
- req.sanitizeBody('email')
- .normalizeEmail({
- gmail_remove_dots: false,
- remove_extension: false,
- gmail_remove_subaddress: false
- });
- req.checkBody('email', 'Email is not valid')
- .custom(value => {
- return User.findOne({email: value}).then(user => {
- if (user) {
- console.log('find user',user);
- return Promise.reject('E-mail already in use');
- }
- });
- });
- req.checkBody('password', 'Password Cannot be Blank!')
- .notEmpty()
- .isLength({min: 6})
- .withMessage('Password must be at least 6 chars long');
- req.checkBody('password2', 'Confirmed Password cannot be blank!').notEmpty();
- req.checkBody('password2', 'Oops! Your passwords do not match').equals(req.body.password);
- const errors = req.validationErrors();
- console.log('erros', errors);
- if (errors) {
- res.render('user/register', {
- errors: errors,
- title: 'Register',
- name: req.body.name,
- email: req.body.email,
- password: req.body.password,
- password2: req.body.password2
- });
- return;
- }
- next(); // there were no errors!
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement