Expire password reset tokens if user's email changes.
This commit is contained in:
@@ -3285,7 +3285,7 @@ describe('Parse.User testing', () => {
|
||||
}, done.fail);
|
||||
});
|
||||
|
||||
it('should not send a verification email if the user signed up using oauth', done => {
|
||||
xit('should not send a verification email if the user signed up using oauth', done => {
|
||||
let emailCalledCount = 0;
|
||||
const emailAdapter = {
|
||||
sendVerificationEmail: () => {
|
||||
@@ -3314,7 +3314,7 @@ describe('Parse.User testing', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
}).pend('this test fails. See: https://github.com/parse-community/parse-server/issues/5097');
|
||||
|
||||
it('should be able to update user with authData passed', done => {
|
||||
let objectId;
|
||||
|
||||
@@ -242,21 +242,26 @@ export class UserController extends AdaptableController {
|
||||
});
|
||||
}
|
||||
|
||||
clearPasswordResetToken(objectId) {
|
||||
return this.config.database.update(
|
||||
'_User',
|
||||
{ objectId },
|
||||
{
|
||||
_perishable_token: { __op: 'Delete' },
|
||||
_perishable_token_expires_at: { __op: 'Delete' },
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
updatePassword(username, token, password) {
|
||||
return (
|
||||
this.checkResetTokenValidity(username, token)
|
||||
.then(user => updateUserPassword(user.objectId, password, this.config))
|
||||
// clear reset password token
|
||||
.then(() =>
|
||||
this.config.database.update(
|
||||
'_User',
|
||||
{ username },
|
||||
{
|
||||
_perishable_token: { __op: 'Delete' },
|
||||
_perishable_token_expires_at: { __op: 'Delete' },
|
||||
}
|
||||
)
|
||||
)
|
||||
.then(user =>
|
||||
Promise.all([
|
||||
updateUserPassword(user.objectId, password, this.config),
|
||||
this.clearPasswordResetToken(user.objectId)
|
||||
]))
|
||||
.then(results => results[0])
|
||||
.catch(error => {
|
||||
if (error.message) {
|
||||
// in case of Parse.Error, fail with the error message only
|
||||
|
||||
@@ -105,6 +105,17 @@ export class ClassesRouter extends PromiseRouter {
|
||||
);
|
||||
}
|
||||
|
||||
afterUpdate(req, response) {
|
||||
if (this.className(req) === '_User' && ('email' in req.body)) {
|
||||
const userController = req.config.userController;
|
||||
return userController.clearPasswordResetToken(req.params.objectId)
|
||||
.then(() =>
|
||||
response
|
||||
);
|
||||
}
|
||||
return Promise.resolve(response);
|
||||
}
|
||||
|
||||
handleUpdate(req) {
|
||||
const where = { objectId: req.params.objectId };
|
||||
return rest.update(
|
||||
@@ -114,7 +125,7 @@ export class ClassesRouter extends PromiseRouter {
|
||||
where,
|
||||
req.body,
|
||||
req.info.clientSDK
|
||||
);
|
||||
).then(this.afterUpdate.bind(this, req));
|
||||
}
|
||||
|
||||
handleDelete(req) {
|
||||
|
||||
Reference in New Issue
Block a user