From c227d1ef55d85d7fe721b262631a9708ad812408 Mon Sep 17 00:00:00 2001 From: Cristina Malin Date: Thu, 12 Oct 2023 12:25:38 +0200 Subject: [PATCH 1/2] Disable reset password for signed in users --- .../ko/runtime/confirm-password.html | 2 +- .../confirm-password/ko/runtime/confirm-password.ts | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/users/confirm-password/ko/runtime/confirm-password.html b/src/components/users/confirm-password/ko/runtime/confirm-password.html index ecd95a41e..2d4228bec 100644 --- a/src/components/users/confirm-password/ko/runtime/confirm-password.html +++ b/src/components/users/confirm-password/ko/runtime/confirm-password.html @@ -20,7 +20,7 @@
-
diff --git a/src/components/users/confirm-password/ko/runtime/confirm-password.ts b/src/components/users/confirm-password/ko/runtime/confirm-password.ts index 78fa1e5ee..ee0af65e3 100644 --- a/src/components/users/confirm-password/ko/runtime/confirm-password.ts +++ b/src/components/users/confirm-password/ko/runtime/confirm-password.ts @@ -21,7 +21,7 @@ export class ConfirmPassword { public readonly password: ko.Observable; public readonly passwordConfirmation: ko.Observable; public readonly isResetConfirmed: ko.Observable; - public readonly working: ko.Observable; + public readonly isResetPasswordDisabled: ko.Observable; constructor( private readonly usersService: UsersService, @@ -29,7 +29,7 @@ export class ConfirmPassword { this.password = ko.observable(); this.passwordConfirmation = ko.observable(); this.isResetConfirmed = ko.observable(false); - this.working = ko.observable(false); + this.isResetPasswordDisabled = ko.observable(false); validation.init({ insertMessages: false, @@ -49,12 +49,15 @@ export class ConfirmPassword { this.userId = await this.usersService.getCurrentUserId(); if (this.userId) { + this.isResetPasswordDisabled(true); + dispatchErrors(this.eventManager, ErrorSources.confirmpassword, ["Cannot reset password for a signed in user."]); return; } const queryParams = new URLSearchParams(location.search); if (!queryParams.has("userid") || !queryParams.has("ticketid") || !queryParams.has("ticket")) { + this.isResetPasswordDisabled(true); dispatchErrors(this.eventManager, ErrorSources.confirmpassword, ["Required params not found"]); return; } @@ -67,6 +70,7 @@ export class ConfirmPassword { throw new Error("User not found."); } } catch (error) { + this.isResetPasswordDisabled(true); dispatchErrors(this.eventManager, ErrorSources.confirmpassword, ["Activate user error: " + error.message]); } } @@ -75,6 +79,11 @@ export class ConfirmPassword { * Sends user resetPswd request to Management API. */ public async resetPswd(): Promise { + if (this.token == undefined || this.userId == undefined) { + dispatchErrors(this.eventManager, ErrorSources.confirmpassword, ["Required params not found"]); + return; + } + const result = validation.group({ password: this.password, passwordConfirmation: this.passwordConfirmation From ebf43166a995a4df02af0e834f4a577e3aed725f Mon Sep 17 00:00:00 2001 From: Cristina Malin Date: Wed, 18 Oct 2023 14:33:52 +0200 Subject: [PATCH 2/2] code review fix --- .../users/confirm-password/ko/runtime/confirm-password.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/components/users/confirm-password/ko/runtime/confirm-password.ts b/src/components/users/confirm-password/ko/runtime/confirm-password.ts index ee0af65e3..fc833e729 100644 --- a/src/components/users/confirm-password/ko/runtime/confirm-password.ts +++ b/src/components/users/confirm-password/ko/runtime/confirm-password.ts @@ -29,7 +29,7 @@ export class ConfirmPassword { this.password = ko.observable(); this.passwordConfirmation = ko.observable(); this.isResetConfirmed = ko.observable(false); - this.isResetPasswordDisabled = ko.observable(false); + this.isResetPasswordDisabled = ko.observable(true); validation.init({ insertMessages: false, @@ -49,7 +49,6 @@ export class ConfirmPassword { this.userId = await this.usersService.getCurrentUserId(); if (this.userId) { - this.isResetPasswordDisabled(true); dispatchErrors(this.eventManager, ErrorSources.confirmpassword, ["Cannot reset password for a signed in user."]); return; } @@ -57,7 +56,6 @@ export class ConfirmPassword { const queryParams = new URLSearchParams(location.search); if (!queryParams.has("userid") || !queryParams.has("ticketid") || !queryParams.has("ticket")) { - this.isResetPasswordDisabled(true); dispatchErrors(this.eventManager, ErrorSources.confirmpassword, ["Required params not found"]); return; } @@ -70,9 +68,10 @@ export class ConfirmPassword { throw new Error("User not found."); } } catch (error) { - this.isResetPasswordDisabled(true); dispatchErrors(this.eventManager, ErrorSources.confirmpassword, ["Activate user error: " + error.message]); } + + this.isResetPasswordDisabled(false); } /**