authelia/src/lib/routes.js

40 lines
804 B
JavaScript
Raw Normal View History

2016-12-10 07:47:58 +07:00
var first_factor = require('./routes/first_factor');
2016-12-10 07:47:58 +07:00
module.exports = {
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) {
serveAuthGet(req, res);
}
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) {
res.render('login');
2016-12-10 07:47:58 +07:00
}
function serveLogout(req, res) {
var redirect_param = req.query.redirect;
var redirect_url = redirect_param || '/';
2016-12-10 07:47:58 +07:00
res.clearCookie('access_token');
res.redirect(redirect_url);
2016-12-10 07:47:58 +07:00
}