From 1a209f2f8c1921146d25f9f94f69530700997d60 Mon Sep 17 00:00:00 2001 From: rr-bw <102181210+rr-bw@users.noreply.github.com> Date: Wed, 7 May 2025 16:11:03 -0700 Subject: [PATCH] [PM-18721] extract some submit logic to handleChangePasswordDelegationFlow() --- .../input-password.component.ts | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/libs/auth/src/angular/input-password/input-password.component.ts b/libs/auth/src/angular/input-password/input-password.component.ts index feb72846b77..4bc8c098e23 100644 --- a/libs/auth/src/angular/input-password/input-password.component.ts +++ b/libs/auth/src/angular/input-password/input-password.component.ts @@ -267,24 +267,13 @@ export class InputPasswordComponent implements OnInit { return; } + const currentPassword = this.formGroup.controls.currentPassword?.value ?? ""; + const newPassword = this.formGroup.controls.newPassword.value; + const newPasswordHint = this.formGroup.controls.newPasswordHint?.value ?? ""; + const checkForBreaches = this.formGroup.controls.checkForBreaches?.value ?? true; + if (this.flow === InputPasswordFlow.ChangePasswordDelegation) { - const newPassword = this.formGroup.controls.newPassword.value; - - const newPasswordVerified = await this.verifyNewPassword( - newPassword, - this.passwordStrengthScore, - false, - ); - if (!newPasswordVerified) { - return; - } - - const passwordInputResult: PasswordInputResult = { - newPassword, - }; - - this.onPasswordFormSubmit.emit(passwordInputResult); - + await this.handleChangePasswordDelegationFlow(newPassword); return; } @@ -292,11 +281,6 @@ export class InputPasswordComponent implements OnInit { throw new Error("Email is required to create master key."); } - const currentPassword = this.formGroup.controls.currentPassword?.value ?? ""; - const newPassword = this.formGroup.controls.newPassword.value; - const newPasswordHint = this.formGroup.controls.newPasswordHint?.value ?? ""; - const checkForBreaches = this.formGroup.controls.checkForBreaches?.value ?? true; - // 1. Determine kdfConfig if (this.flow === InputPasswordFlow.SetInitialPasswordAccountRegistration) { this.kdfConfig = DEFAULT_KDF_CONFIG; @@ -445,6 +429,23 @@ export class InputPasswordComponent implements OnInit { } } + private async handleChangePasswordDelegationFlow(newPassword: string) { + const newPasswordVerified = await this.verifyNewPassword( + newPassword, + this.passwordStrengthScore, + false, + ); + if (!newPasswordVerified) { + return; + } + + const passwordInputResult: PasswordInputResult = { + newPassword, + }; + + this.onPasswordFormSubmit.emit(passwordInputResult); + } + /** * Returns `true` if the current password is correct (it can be used to successfully decrypt * the masterKeyEncrypedUserKey), `false` otherwise