diff options
| author | nanalelfe <nargiza.nosirova@mail.utoronto.ca> | 2016-07-22 08:18:26 +0000 |
|---|---|---|
| committer | nanalelfe <nargiza.nosirova@mail.utoronto.ca> | 2016-07-22 08:18:26 +0000 |
| commit | 2a7e01b63e58db7ce0ef19210aef9874e022a7c5 (patch) | |
| tree | ce22bfbbf5e9f908d8aa10817549c93bb4a05d30 /routes | |
| parent | e0da9feb10efd002f6ebaa99870b4317687a4557 (diff) | |
Added validation checks for signup
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/index.js | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/routes/index.js b/routes/index.js index b6db0ca..cd527b7 100644 --- a/routes/index.js +++ b/routes/index.js @@ -160,15 +160,20 @@ router.get('/signup', function(req, res, next) { }); -/*router.post('/signup', passport.authenticate('local_signup', { - successRedirect: '/user_profile', - failureRedirect: '/signup', - failureFlash: true -}));*/ +router.get('/signin', function (req, res, next) { + res.render('signin', {csrfToken: req.csrfToken(), success: req.session.success, errors: req.session.errors}); +}); + router.post('/signup', function(req, res, next) { - req.check('email', 'Invalid email address').isEmail(); - req.check('password', "Password is invalid").isLength({min: 6}).equals(req.body.confirmPassword); + req.check('fname', 'Please enter a valid first name.').notEmpty().withMessage('First name required.').isAlpha(); + req.check('lname', 'Please enter a valid first name.').notEmpty().withMessage('Last name required.').isAlpha(); + req.check('email', 'Enter a valid Email address').notEmpty().withMessage('Email required').isEmail(); + req.check('usrname', 'Enter a valid username').notEmpty().withMessage('Username required.').isAlphanumeric(); + req.check('password', "Password should be between 6 and 12 characters.") + .notEmpty().withMessage('Password required').isLength({min: 6, max: 12}); + req.check('password', "The confirmation password doesn't match.").equals(req.body.confirmPassword); + req.check('phone_num', 'Please enter a valid phone number').optional().isMobilePhone('en-CA'); // password has to be at least 4 characters long var errors = req.validationErrors(); @@ -183,16 +188,34 @@ router.post('/signup', function(req, res, next) { failureRedirect: '/signup', failureFlash: true })(req, res); + } //res.redirect('/signup'); }); -/*router.post('/signup', passport.authenticate('local.signup', { - sucessRedirect: '/profile', - failureRedirect: '/signup', - failureFlash: true -}));*/ +router.post('/signin', function(req, res, next) { + req.check('usrname', 'Username field is empty.').notEmpty(); + req.check('password', "Password field is empty.").notEmpty(); + // password has to be at least 4 characters long + + var errors = req.validationErrors(); + if (errors) { + req.session.errors = errors; + req.session.success = false; + res.redirect('/signin'); + } else { + console.log("GOT SUCCESS"); + passport.authenticate('local_signin', { + successRedirect: '/user_profile', + failureRedirect: '/signin', + failureFlash: true + })(req, res); + + } + //res.redirect('/signup'); + +}); /**** Helpers ****/ |
