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 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);
|
||||||
|
|
Loading…
Reference in New Issue