Skip to content

Commit f64721a

Browse files
authored
Merge pull request #3073 from strongloop/backport/resetPasswordRequest-options
Emit resetPasswordRequest event with options
2 parents 0caee53 + 5233dcb commit f64721a

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

common/models/user.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,8 @@ module.exports = function(User) {
613613
UserModel.emit('resetPasswordRequest', {
614614
email: options.email,
615615
accessToken: accessToken,
616-
user: user
616+
user: user,
617+
options: options,
617618
});
618619
});
619620
});

test/user.test.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,10 @@ describe('User', function() {
18061806

18071807
describe('Password Reset', function() {
18081808
describe('User.resetPassword(options, cb)', function() {
1809-
var email = '[email protected]';
1809+
var options = {
1810+
1811+
redirect: 'http://foobar.com/reset-password',
1812+
};
18101813

18111814
it('Requires email address to reset password', function(done) {
18121815
User.resetPassword({ }, function(err) {
@@ -1840,11 +1843,27 @@ describe('User', function() {
18401843
});
18411844
});
18421845

1846+
it('Checks that options exist', function(done) {
1847+
var calledBack = false;
1848+
1849+
User.resetPassword(options, function() {
1850+
calledBack = true;
1851+
});
1852+
1853+
User.once('resetPasswordRequest', function(info) {
1854+
assert(info.options);
1855+
assert.equal(info.options, options);
1856+
assert(calledBack);
1857+
1858+
done();
1859+
});
1860+
});
1861+
18431862
it('Creates a temp accessToken to allow a user to change password', function(done) {
18441863
var calledBack = false;
18451864

18461865
User.resetPassword({
1847-
email: email
1866+
email: options.email,
18481867
}, function() {
18491868
calledBack = true;
18501869
});
@@ -1858,7 +1877,7 @@ describe('User', function() {
18581877
info.accessToken.user(function(err, user) {
18591878
if (err) return done(err);
18601879

1861-
assert.equal(user.email, email);
1880+
assert.equal(user.email, options.email);
18621881

18631882
done();
18641883
});
@@ -1887,7 +1906,7 @@ describe('User', function() {
18871906
.post('/test-users/reset')
18881907
.expect('Content-Type', /json/)
18891908
.expect(204)
1890-
.send({ email: email })
1909+
.send({email: options.email})
18911910
.end(function(err, res) {
18921911
if (err) return done(err);
18931912

0 commit comments

Comments
 (0)