Autenticación por email o usuario
This commit is contained in:
parent
ac3f7c2da0
commit
3f84230619
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue