Adds ability to expire email verify token (#2216)
This commit is contained in:
committed by
Drew
parent
033bc317e6
commit
6f292059ba
@@ -36,6 +36,10 @@ export class UserController extends AdaptableController {
|
||||
if (this.shouldVerifyEmails) {
|
||||
user._email_verify_token = randomString(25);
|
||||
user.emailVerified = false;
|
||||
|
||||
if (this.config.emailVerifyTokenValidityDuration) {
|
||||
user._email_verify_token_expires_at = Parse._encode(this.config.generateEmailVerifyTokenExpiresAt());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,10 +49,20 @@ export class UserController extends AdaptableController {
|
||||
// TODO: Better error here.
|
||||
throw undefined;
|
||||
}
|
||||
return this.config.database.update('_User', {
|
||||
username: username,
|
||||
_email_verify_token: token
|
||||
}, {emailVerified: true}).then(document => {
|
||||
|
||||
let query = {username: username, _email_verify_token: token};
|
||||
let updateFields = { emailVerified: true, _email_verify_token: {__op: 'Delete'}};
|
||||
|
||||
// if the email verify token needs to be validated then
|
||||
// add additional query params and additional fields that need to be updated
|
||||
if (this.config.emailVerifyTokenValidityDuration) {
|
||||
query.emailVerified = false;
|
||||
query._email_verify_token_expires_at = { $gt: Parse._encode(new Date()) };
|
||||
|
||||
updateFields._email_verify_token_expires_at = {__op: 'Delete'};
|
||||
}
|
||||
|
||||
return this.config.database.update('_User', query, updateFields).then((document) => {
|
||||
if (!document) {
|
||||
throw undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user