diff options
| author | nanalelfe <nargiza.nosirova@mail.utoronto.ca> | 2016-08-23 08:51:35 +0000 |
|---|---|---|
| committer | nanalelfe <nargiza.nosirova@mail.utoronto.ca> | 2016-08-23 08:51:35 +0000 |
| commit | eb6336f3570e100992a3dd1fa7826cd0245098e3 (patch) | |
| tree | 428471ca31a74f7d5296004fc77a9a0ecf39f48e /routes | |
| parent | 31016bd38e07668236d1e1257e2d40a3fde34fe5 (diff) | |
Implemented admin signin
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/admin.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/routes/admin.js b/routes/admin.js index 6a628d2..425dcc0 100644 --- a/routes/admin.js +++ b/routes/admin.js @@ -52,6 +52,27 @@ router.get('/signin', function (req, res, next) { }); }); +/** Retrieves infomation from the signin form, form validates and sends it to passport.js to authenticate. */ +router.post('/signin', function(req, res, next) { + req.check('usrname', 'Username field is empty.').notEmpty(); + req.check('password', "Password field is empty.").notEmpty(); + + var errors = req.validationErrors(); + if (errors) { + req.session.errors = errors; + req.session.success = false; + res.redirect('/admin/signin'); + } else { + passport.authenticate('admin_signin', { + successRedirect: '/admin/', + failureRedirect: '/admin/signin', + failureFlash: true + })(req, res); + } + + +}); + /** Retrieves infomation from the exam adding form and sends it to the database to add. */ router.post('/add/exam', function(req,res){ req.sanitize('course_code').escape(); |
