refactor on routes.js

This commit is contained in:
Carlos 2017-09-22 13:06:38 +02:00
parent 05456cd185
commit a5df4afc0f
1 changed files with 6 additions and 7 deletions

View File

@ -5,7 +5,7 @@ module.exports = function(app) {
let User = app.models.User;
let applications = app.get('applications');
app.get('/',function(req, res){
app.get('/', function(req, res) {
res.render('index.ejs');
});
@ -29,12 +29,11 @@ module.exports = function(app) {
}
function loginCb(err, token) {
if (err) {
if(syncOnFail && !usesEmail) {
if (syncOnFail && !usesEmail) {
syncOnFail = false;
let filter = {where: {name: user}};
app.models.Account.findOne(filter, findCb);
}
else
} else
badLogin();
return;
}
@ -48,11 +47,11 @@ module.exports = function(app) {
res.send(JSON.stringify({
token: token.id,
continue: query.continue,
loginUrl: loginUrl,
loginUrl: loginUrl
}));
}
function findCb(err, instance) {
if(!instance || instance.password !== md5(password)) {
if (!instance || instance.password !== md5(password)) {
badLogin();
return;
}
@ -76,7 +75,7 @@ module.exports = function(app) {
}
});
app.get('/logout', function (req, res) {
app.get('/logout', function(req, res) {
User.logout(req.accessToken.id,
() => res.redirect('/'));
});