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 user = req.body.user;
let password = req.body.password; let password = req.body.password;
let syncOnFail = true; let syncOnFail = true;
let usesEmail = user.indexOf('@') !== -1;
login(); login();
function login() { function login() {
let loginInfo = { let loginInfo = {password: password};
username: user,
password: password if (usesEmail)
}; loginInfo.email = user;
else
loginInfo.username = user;
User.login(loginInfo, 'user', loginCb); User.login(loginInfo, 'user', loginCb);
} }
function loginCb(err, token) { function loginCb(err, token) {
if (err) { if (err) {
if(syncOnFail) { if(syncOnFail && !usesEmail) {
syncOnFail = false; syncOnFail = false;
let filter = {where: {name: user}}; let filter = {where: {name: user}};
app.models.Account.findOne(filter, findCb); app.models.Account.findOne(filter, findCb);