diff --git a/services/auth/server/boot/routes.js b/services/auth/server/boot/routes.js index 8ef324235..1c49fa0f7 100644 --- a/services/auth/server/boot/routes.js +++ b/services/auth/server/boot/routes.js @@ -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);