Allow users to be verified with both emails if cloudron mail is enabled
This commit is contained in:
@@ -576,6 +576,25 @@ describe('User', function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('succeeds for both emails with cloudron mail', function (done) {
|
||||||
|
// user settingsdb instead of settings, to not trigger further events
|
||||||
|
settingsdb.set(settings.MAIL_CONFIG_KEY, JSON.stringify({ enabled: true }), function (error) {
|
||||||
|
expect(error).not.to.be.ok();
|
||||||
|
|
||||||
|
user.verifyWithEmail(EMAIL, PASSWORD, function (error, result) {
|
||||||
|
expect(error).to.not.be.ok();
|
||||||
|
expect(result).to.be.ok();
|
||||||
|
|
||||||
|
user.verifyWithEmail(USERNAME + '@' + config.fqdn(), PASSWORD, function (error, result) {
|
||||||
|
expect(error).to.not.be.ok();
|
||||||
|
expect(result).to.be.ok();
|
||||||
|
|
||||||
|
settingsdb.set(settings.MAIL_CONFIG_KEY, JSON.stringify({ enabled: false }), done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('retrieving', function () {
|
describe('retrieving', function () {
|
||||||
|
|||||||
12
src/user.js
12
src/user.js
@@ -264,11 +264,17 @@ function verifyWithEmail(email, password, callback) {
|
|||||||
assert.strictEqual(typeof password, 'string');
|
assert.strictEqual(typeof password, 'string');
|
||||||
assert.strictEqual(typeof callback, 'function');
|
assert.strictEqual(typeof callback, 'function');
|
||||||
|
|
||||||
userdb.getByEmail(email.toLowerCase(), function (error, user) {
|
settings.getMailConfig(function (error, mailConfig) {
|
||||||
if (error && error.reason == DatabaseError.NOT_FOUND) return callback(new UserError(UserError.NOT_FOUND));
|
|
||||||
if (error) return callback(new UserError(UserError.INTERNAL_ERROR, error));
|
if (error) return callback(new UserError(UserError.INTERNAL_ERROR, error));
|
||||||
|
|
||||||
verify(user.id, password, callback);
|
if (mailConfig.enabled) return verifyWithUsername(email.split('@')[0], password, callback);
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user