authelia/src/lib/routes.js

43 lines
784 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) {
res.clearCookie('access_token');
res.redirect('/');
}