Fix case when username is not the same as the email

This commit is contained in:
Johannes Zellner
2016-09-27 15:41:34 +02:00
parent 656356732e
commit 23bf358bbe
2 changed files with 15 additions and 6 deletions

View File

@@ -264,17 +264,26 @@ function verifyWithEmail(email, password, callback) {
assert.strictEqual(typeof password, 'string');
assert.strictEqual(typeof callback, 'function');
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);
function checkWithEmailFromDatabase() {
userdb.getByEmail(email.toLowerCase(), 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();
});
});
}