2016-11-08 14:06:45 +00:00
|
|
|
var url = require ('url');
|
|
|
|
|
2016-11-08 08:07:39 +00:00
|
|
|
module.exports = function(app) {
|
2017-05-17 19:23:47 +00:00
|
|
|
let applications = app.get('applications');
|
2016-11-08 08:07:39 +00:00
|
|
|
|
2017-05-17 19:23:47 +00:00
|
|
|
app.get('/',function(req, res){
|
|
|
|
res.render('index.ejs');
|
|
|
|
});
|
|
|
|
|
|
|
|
app.post('/login', function(req, res) {
|
|
|
|
app.models.User.login({
|
|
|
|
email: req.body.email,
|
|
|
|
password: req.body.password
|
|
|
|
}, 'user', function(err, token) {
|
|
|
|
if (err) {
|
|
|
|
res.status (401);
|
|
|
|
res.send(JSON.stringify({
|
|
|
|
title: 'Login failed',
|
|
|
|
content: err,
|
|
|
|
redirectTo: '/',
|
|
|
|
redirectToLinkText: 'Try again'
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
let query = url.parse(req.body.location, true).query;
|
|
|
|
let loginUrl = applications[query.apiKey];
|
|
|
|
if (!loginUrl)
|
|
|
|
loginUrl = applications.default;
|
|
|
|
|
|
|
|
res.send(JSON.stringify({
|
|
|
|
token: token.id,
|
|
|
|
continue: query.continue,
|
|
|
|
loginUrl: loginUrl,
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
});
|
2016-11-08 08:07:39 +00:00
|
|
|
});
|
2016-11-08 14:06:45 +00:00
|
|
|
|
2017-05-17 19:23:47 +00:00
|
|
|
app.get('/logout', function (req, res) {
|
|
|
|
app.models.User.logout(req.accessToken.id, function(err) {
|
|
|
|
res.redirect('/');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|