Skip to content

Commit 82ebba4

Browse files
committed
Merge pull request #1133 from carmenlau/reset-password-fix
Reset password fix
2 parents ee8f85b + 603bf97 commit 82ebba4

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

spec/ValidationAndPasswordsReset.spec.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,15 @@ describe("Password Reset", () => {
573573
expect(response.body).toEqual('Found. Redirecting to http://localhost:8378/1/apps/password_reset_success.html');
574574

575575
Parse.User.logIn("zxcv", "hello").then(function(user){
576-
done();
576+
let config = new Config('test');
577+
config.database.adaptiveCollection('_User')
578+
.then(coll => coll.find({ 'username': 'zxcv' }, { limit: 1 }))
579+
.then((results) => {
580+
// _perishable_token should be unset after reset password
581+
expect(results.length).toEqual(1);
582+
expect(results[0]['_perishable_token']).toEqual(undefined);
583+
done();
584+
});
577585
}, (err) => {
578586
console.error(err);
579587
fail("should login with new password");

src/Controllers/UserController.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { randomString } from '../cryptoUtils';
22
import { inflate } from '../triggers';
33
import AdaptableController from './AdaptableController';
44
import MailAdapter from '../Adapters/Email/MailAdapter';
5+
import rest from '../rest';
56

67
var DatabaseAdapter = require('../DatabaseAdapter');
78
var RestWrite = require('../RestWrite');
@@ -165,9 +166,17 @@ export class UserController extends AdaptableController {
165166
}
166167

167168
updatePassword(username, token, password, config) {
168-
return this.checkResetTokenValidity(username, token).then(() => {
169-
return updateUserPassword(username, token, password, this.config);
170-
});
169+
return this.checkResetTokenValidity(username, token).then((user) => {
170+
return updateUserPassword(user._id, password, this.config);
171+
}).then(() => {
172+
// clear reset password token
173+
return this.config.database.adaptiveCollection('_User').then(function (collection) {
174+
// Need direct database access because verification token is not a parse field
175+
return collection.findOneAndUpdate({ username: username },// query
176+
{ $unset: { _perishable_token: null } } // update
177+
);
178+
});
179+
});
171180
}
172181

173182
defaultVerificationEmail({link, user, appName, }) {
@@ -192,12 +201,10 @@ export class UserController extends AdaptableController {
192201
}
193202

194203
// Mark this private
195-
function updateUserPassword(username, token, password, config) {
196-
var write = new RestWrite(config, Auth.master(config), '_User', {
197-
username: username,
198-
_perishable_token: token
199-
}, {password: password, _perishable_token: null }, undefined);
200-
return write.execute();
204+
function updateUserPassword(userId, password, config) {
205+
return rest.update(config, Auth.master(config), '_User', userId, {
206+
password: password
207+
});
201208
}
202209

203210
export default UserController;

0 commit comments

Comments
 (0)