2016-12-10 07:47:58 +07:00
|
|
|
|
2017-01-19 07:01:37 +07:00
|
|
|
var first_factor = require('./routes/first_factor');
|
|
|
|
|
2016-12-10 07:47:58 +07:00
|
|
|
module.exports = {
|
2017-01-19 07:01:37 +07:00
|
|
|
auth: serveAuth,
|
|
|
|
login: serveLogin,
|
|
|
|
logout: serveLogout,
|
|
|
|
first_factor: first_factor
|
2016-12-10 07:47:58 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
var authentication = require('./authentication');
|
|
|
|
var replies = require('./replies');
|
|
|
|
|
|
|
|
function serveAuth(req, res) {
|
2017-01-19 07:01:37 +07:00
|
|
|
serveAuthGet(req, res);
|
2016-12-17 08:06:40 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
function serveAuthGet(req, res) {
|
2016-12-10 07:47:58 +07:00
|
|
|
authentication.verify(req, res)
|
|
|
|
.then(function(user) {
|
|
|
|
replies.already_authenticated(res, user);
|
|
|
|
})
|
2017-01-19 07:44:24 +07:00
|
|
|
.catch(function(err) {
|
2016-12-10 07:47:58 +07:00
|
|
|
replies.authentication_failed(res);
|
|
|
|
console.error(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function serveLogin(req, res) {
|
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 || '/';
|
2016-12-10 07:47:58 +07:00
|
|
|
res.clearCookie('access_token');
|
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
|
|
|
|