diff --git a/src/user.js b/src/user.js index 52efcd0fb..a08ec8660 100644 --- a/src/user.js +++ b/src/user.js @@ -266,26 +266,17 @@ function verifyWithEmail(email, password, callback) { email = email.toLowerCase(); - function checkWithEmailFromDatabase() { + settings.getMailConfig(function (error, mailConfig) { + if (error) return callback(new UserError(UserError.INTERNAL_ERROR, error)); + + if (mailConfig.enabled) return verifyWithUsername(email.split('@')[0], password, callback); + userdb.getByEmail(email, function (error, user) { if (error && error.reason == DatabaseError.NOT_FOUND) return callback(new UserError(UserError.NOT_FOUND)); if (error) return callback(new UserError(UserError.INTERNAL_ERROR, error)); verify(user.id, password, callback); }); - } - - settings.getMailConfig(function (error, mailConfig) { - if (error) return callback(new UserError(UserError.INTERNAL_ERROR, error)); - - if (!mailConfig.enabled) return checkWithEmailFromDatabase(); - - verifyWithUsername(email.split('@')[0], password, function (error, result) { - if (!error) return callback(null, result); - if (error.reason !== UserError.NOT_FOUND) return callback(error); - - checkWithEmailFromDatabase(); - }); }); }