2016-12-10 07:47:58 +07:00
|
|
|
|
2017-01-19 07:01:37 +07:00
|
|
|
var first_factor = require('./routes/first_factor');
|
2017-01-21 23:41:06 +07:00
|
|
|
var second_factor = require('./routes/second_factor');
|
2017-01-27 07:20:03 +07:00
|
|
|
var reset_password = require('./routes/reset_password');
|
2017-01-21 23:41:06 +07:00
|
|
|
var verify = require('./routes/verify');
|
2017-01-27 07:20:03 +07:00
|
|
|
var u2f_register_handler = require('./routes/u2f_register_handler');
|
2017-01-29 00:27:54 +07:00
|
|
|
var totp_register = require('./routes/totp_register');
|
2017-01-22 23:54:45 +07:00
|
|
|
var objectPath = require('object-path');
|
2017-01-19 07:01:37 +07:00
|
|
|
|
2016-12-10 07:47:58 +07:00
|
|
|
module.exports = {
|
2017-01-19 07:01:37 +07:00
|
|
|
login: serveLogin,
|
|
|
|
logout: serveLogout,
|
2017-01-21 23:41:06 +07:00
|
|
|
verify: verify,
|
|
|
|
first_factor: first_factor,
|
2017-01-27 07:20:03 +07:00
|
|
|
second_factor: second_factor,
|
|
|
|
reset_password: reset_password,
|
2017-01-29 00:27:54 +07:00
|
|
|
u2f_register: u2f_register_handler,
|
|
|
|
totp_register: totp_register,
|
2016-12-10 07:47:58 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
function serveLogin(req, res) {
|
2017-01-22 23:54:45 +07:00
|
|
|
if(!(objectPath.has(req, 'session.auth_session'))) {
|
|
|
|
req.session.auth_session = {};
|
|
|
|
req.session.auth_session.first_factor = false;
|
|
|
|
req.session.auth_session.second_factor = false;
|
|
|
|
}
|
2016-12-17 08:06:40 +07:00
|
|
|
res.render('login');
|
2016-12-10 07:47:58 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
function serveLogout(req, res) {
|
2016-12-18 01:36:41 +07:00
|
|
|
var redirect_param = req.query.redirect;
|
|
|
|
var redirect_url = redirect_param || '/';
|
2017-01-21 23:41:06 +07:00
|
|
|
req.session.auth_session = {
|
|
|
|
first_factor: false,
|
|
|
|
second_factor: false
|
|
|
|
}
|
2016-12-18 01:36:41 +07:00
|
|
|
res.redirect(redirect_url);
|
2016-12-10 07:47:58 +07:00
|
|
|
}
|
2016-12-18 01:36:41 +07:00
|
|
|
|