-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.js
34 lines (27 loc) · 849 Bytes
/
auth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var express = require('express');
var passport = require('passport');
var router = express.Router();
/* GET users listing. */
router.get('/login', function(req, res, next) {
res.render('login');
});
router.post('/login/password', passport.authenticate('local', {
successRedirect: '/login/otp', // TODO: make this contextual on the session
failureRedirect: '/login',
failureMessage: true
}));
router.get('/login/otp', function(req, res, next) {
res.render('login/otp');
});
router.post('/login/otp/2',
// TODO: ensure authenticated
passport.authenticate('totp', { failureRedirect: '/login/otp/2', failureFlash: true }),
function(req, res) {
//req.session.secondFactor = 'totp';
res.redirect('/');
});
router.get('/logout', function(req, res, next) {
req.logout();
res.redirect('/');
});
module.exports = router;