Autenticación por email o usuario

This commit is contained in:
Juan Ferrer Toribio 2017-05-22 11:31:06 +02:00
parent ac3f7c2da0
commit 3f84230619
1 changed files with 9 additions and 5 deletions

View File

@ -13,19 +13,23 @@ module.exports = function(app) {
let user = req.body.user;
let password = req.body.password;
let syncOnFail = true;
let usesEmail = user.indexOf('@') !== -1;
login();
function login() {
let loginInfo = {
username: user,
password: password
};
let loginInfo = {password: password};
if (usesEmail)
loginInfo.email = user;
else
loginInfo.username = user;
User.login(loginInfo, 'user', loginCb);
}
function loginCb(err, token) {
if (err) {
if(syncOnFail) {
if(syncOnFail && !usesEmail) {
syncOnFail = false;
let filter = {where: {name: user}};
app.models.Account.findOne(filter, findCb);