Skip to content

Commit f983311

Browse files
flovilmartRafael Santos
authored andcommitted
Creates a new sessionToken when updating password (parse-community#2266)
* Creates a new sessionToken when updating password * Adds test ensuring email is properly sent when upgrading from anon
1 parent 1710ee4 commit f983311

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/RestWrite.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ RestWrite.prototype.transformUser = function() {
367367
}
368368
if (this.query && !this.auth.isMaster ) {
369369
this.storage['clearSessions'] = true;
370+
this.storage['generateNewSession'] = true;
370371
}
371372
return passwordCrypto.hash(this.data.password).then((hashedPassword) => {
372373
this.data._hashed_password = hashedPassword;
@@ -428,6 +429,10 @@ RestWrite.prototype.createSessionTokenIfNeeded = function() {
428429
if (this.query) {
429430
return;
430431
}
432+
return this.createSessionToken();
433+
}
434+
435+
RestWrite.prototype.createSessionToken = function() {
431436
var token = 'r:' + cryptoUtils.newToken();
432437

433438
var expiresAt = this.config.generateSessionExpiresAt();
@@ -464,15 +469,21 @@ RestWrite.prototype.handleFollowup = function() {
464469
}
465470
};
466471
delete this.storage['clearSessions'];
467-
this.config.database.destroy('_Session', sessionQuery)
472+
return this.config.database.destroy('_Session', sessionQuery)
473+
.then(this.handleFollowup.bind(this));
474+
}
475+
476+
if (this.storage && this.storage['generateNewSession']) {
477+
delete this.storage['generateNewSession'];
478+
return this.createSessionToken()
468479
.then(this.handleFollowup.bind(this));
469480
}
470481

471482
if (this.storage && this.storage['sendVerificationEmail']) {
472483
delete this.storage['sendVerificationEmail'];
473484
// Fire and forget!
474485
this.config.userController.sendVerificationEmail(this.data);
475-
this.handleFollowup.bind(this);
486+
return this.handleFollowup.bind(this);
476487
}
477488
};
478489

0 commit comments

Comments
 (0)