aboutsummaryrefslogtreecommitdiff
path: root/routes
diff options
context:
space:
mode:
Diffstat (limited to 'routes')
-rw-r--r--routes/index.js47
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 ****/