Skip to content

Commit b8f9b85

Browse files
JonnyBGodbajtos
authored andcommitted
Fix User.resetPassword to call createAccessToken()
This allows User subclasses to override the algorithm used for building one-time access tokens for password recovery.
1 parent d35e1a1 commit b8f9b85

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

common/models/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ module.exports = function(User) {
605605
return cb(err);
606606
}
607607

608-
user.accessTokens.create({ ttl: ttl }, function(err, accessToken) {
608+
user.createAccessToken(ttl, function(err, accessToken) {
609609
if (err) {
610610
return cb(err);
611611
}

test/user.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,19 @@ describe('User', function() {
18841884
});
18851885
});
18861886

1887+
it('calls createAccessToken() to create the token', function(done) {
1888+
User.prototype.createAccessToken = function(ttl, cb) {
1889+
cb(null, new AccessToken({id: 'custom-token'}));
1890+
};
1891+
1892+
User.resetPassword({email: options.email}, function() {});
1893+
1894+
User.once('resetPasswordRequest', function(info) {
1895+
expect(info.accessToken.id).to.equal('custom-token');
1896+
done();
1897+
});
1898+
});
1899+
18871900
it('Password reset over REST rejected without email address', function(done) {
18881901
request(app)
18891902
.post('/test-users/reset')

0 commit comments

Comments
 (0)