authelia/src/lib/routes.js

46 lines
881 B
JavaScript
Raw Normal View History

2016-12-10 07:47:58 +07:00
module.exports = {
'auth': serveAuth,
'login': serveLogin,
'logout': serveLogout
}
var authentication = require('./authentication');
var replies = require('./replies');
function serveAuth(req, res) {
if(req.method == 'POST') {
serveAuthPost(req, res);
}
else {
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);
})
.fail(function(err) {
replies.authentication_failed(res);
console.error(err);
});
}
function serveAuthPost(req, res) {
authentication.authenticate(req, res);
}
2016-12-10 07:47:58 +07:00
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
}