Skip to content

Commit

Permalink
[NEW] REST endpoint to recover forgotten password (#10371)
Browse files Browse the repository at this point in the history
* Add REST /forgotPassword endpoint and tests

* Add REST /forgotPassword endpoint and tests

* Remove endpoint, from wrong file

* Moving endpoint from /forgotPassword to /users.forgotPassword
  • Loading branch information
MarcosSpessatto authored and sampaiodiego committed Apr 17, 2018
1 parent 5187149 commit 16b6190
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/rocketchat-api/server/v1/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,18 @@ RocketChat.API.v1.addRoute('user.roles', { authRequired: true }, {
}));
}
});

RocketChat.API.v1.addRoute('users.forgotPassword', { authRequired: false }, {
post() {
const { email } = this.bodyParams;
if (!email) {
return RocketChat.API.v1.failure('The \'email\' param is required');
}

const emailSent = Meteor.call('sendForgotPasswordEmail', email);
if (emailSent) {
return RocketChat.API.v1.success();
}
return RocketChat.API.v1.failure('User not found');
}
});
28 changes: 28 additions & 0 deletions tests/end-to-end/api/01-users.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,4 +589,32 @@ describe('[Users]', function() {
.end(done);
});
});

describe('[/users.forgotPassword]', () => {
it('should send email to user (return success), when is a valid email', (done) => {
request.post(api('users.forgotPassword'))
.send({
email: adminEmail
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
})
.end(done);
});

it('should not send email to user(return error), when is a invalid email', (done) => {
request.post(api('users.forgotPassword'))
.send({
email: 'invalidEmail'
})
.expect('Content-Type', 'application/json')
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
})
.end(done);
});
});
});

0 comments on commit 16b6190

Please sign in to comment.