diff --git a/src/routes/cloudron.js b/src/routes/cloudron.js index b498b468a..a4e7ceabb 100644 --- a/src/routes/cloudron.js +++ b/src/routes/cloudron.js @@ -86,7 +86,7 @@ function logout(req, res) { function passwordResetRequest(req, res, next) { if (!req.body.identifier || typeof req.body.identifier !== 'string') return next(new HttpError(401, 'A identifier must be non-empty string')); - users.resetPasswordByIdentifier(req.body.identifier, function (error) { + users.sendPasswordResetByIdentifier(req.body.identifier, function (error) { if (error && error.reason !== BoxError.NOT_FOUND) return next(BoxError.toHttpError(error)); next(new HttpSuccess(202, {})); diff --git a/src/test/users-test.js b/src/test/users-test.js index 4722a5baa..a514eaae5 100644 --- a/src/test/users-test.js +++ b/src/test/users-test.js @@ -912,12 +912,12 @@ describe('User', function () { }); }); - describe('resetPasswordByIdentifier', function () { + describe('sendPasswordResetByIdentifier', function () { before(createOwner); after(cleanupUsers); it('fails due to unkown email', function (done) { - users.resetPasswordByIdentifier('unknown@mail.com', function (error) { + users.sendPasswordResetByIdentifier('unknown@mail.com', function (error) { expect(error).to.be.an(BoxError); expect(error.reason).to.eql(BoxError.NOT_FOUND); done(); @@ -925,7 +925,7 @@ describe('User', function () { }); it('fails due to unkown username', function (done) { - users.resetPasswordByIdentifier('unknown', function (error) { + users.sendPasswordResetByIdentifier('unknown', function (error) { expect(error).to.be.an(BoxError); expect(error.reason).to.eql(BoxError.NOT_FOUND); done(); @@ -933,14 +933,14 @@ describe('User', function () { }); it('succeeds with email', function (done) { - users.resetPasswordByIdentifier(EMAIL, function (error) { + users.sendPasswordResetByIdentifier(EMAIL, function (error) { expect(error).to.not.be.ok(); checkMails(1, done); }); }); it('succeeds with username', function (done) { - users.resetPasswordByIdentifier(USERNAME, function (error) { + users.sendPasswordResetByIdentifier(USERNAME, function (error) { expect(error).to.not.be.ok(); checkMails(1, done); }); diff --git a/src/users.js b/src/users.js index 999136c7f..4bc289e9f 100644 --- a/src/users.js +++ b/src/users.js @@ -16,7 +16,6 @@ exports = module.exports = { getByResetToken: getByResetToken, getByUsername: getByUsername, getAdmins: getAdmins, - resetPasswordByIdentifier: resetPasswordByIdentifier, setPassword: setPassword, update: updateUser, createOwner: createOwner, @@ -28,6 +27,8 @@ exports = module.exports = { enableTwoFactorAuthentication: enableTwoFactorAuthentication, disableTwoFactorAuthentication: disableTwoFactorAuthentication, + sendPasswordResetByIdentifier: sendPasswordResetByIdentifier, + count: count, AP_MAIL: 'mail', @@ -484,13 +485,11 @@ function getAdmins(callback) { }); } -function resetPasswordByIdentifier(identifier, callback) { +function sendPasswordResetByIdentifier(identifier, callback) { assert.strictEqual(typeof identifier, 'string'); assert.strictEqual(typeof callback, 'function'); - var getter; - if (identifier.indexOf('@') === -1) getter = userdb.getByUsername; - else getter = userdb.getByEmail; + const getter = identifier.indexOf('@') === -1 ? userdb.getByUsername : userdb.getByEmail; getter(identifier.toLowerCase(), function (error, result) { if (error) return callback(error);