From 02c524dd5f6df6cad3bf450a18ba6db3ed833515 Mon Sep 17 00:00:00 2001 From: KiruthigaManivannan <162679756+KiruthigaManivannan@users.noreply.github.com> Date: Thu, 23 May 2024 20:47:11 +0530 Subject: [PATCH] PM-2058 Update Two Factor Recovery Dialog (#8985) --- .../two-factor-recovery.component.html | 62 +++++++------------ .../settings/two-factor-recovery.component.ts | 15 ++++- .../settings/two-factor-setup.component.html | 1 - .../settings/two-factor-setup.component.ts | 6 +- 4 files changed, 38 insertions(+), 46 deletions(-) diff --git a/apps/web/src/app/auth/settings/two-factor-recovery.component.html b/apps/web/src/app/auth/settings/two-factor-recovery.component.html index 93cbab8b92a..98676509078 100644 --- a/apps/web/src/app/auth/settings/two-factor-recovery.component.html +++ b/apps/web/src/app/auth/settings/two-factor-recovery.component.html @@ -1,39 +1,23 @@ - + + + {{ "twoStepLogin" | i18n }} + {{ "recoveryCodeTitle" | i18n }} + + + +

{{ "twoFactorRecoveryYourCode" | i18n }}:

+ {{ code }} +
+ + {{ "twoFactorRecoveryNoCode" | i18n }} + +
+ + + + +
diff --git a/apps/web/src/app/auth/settings/two-factor-recovery.component.ts b/apps/web/src/app/auth/settings/two-factor-recovery.component.ts index 6cbc03c6b44..35f6f686d95 100644 --- a/apps/web/src/app/auth/settings/two-factor-recovery.component.ts +++ b/apps/web/src/app/auth/settings/two-factor-recovery.component.ts @@ -1,8 +1,10 @@ -import { Component } from "@angular/core"; +import { DIALOG_DATA, DialogConfig } from "@angular/cdk/dialog"; +import { Component, Inject } from "@angular/core"; import { TwoFactorProviderType } from "@bitwarden/common/auth/enums/two-factor-provider-type"; import { TwoFactorRecoverResponse } from "@bitwarden/common/auth/models/response/two-factor-recover.response"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; +import { DialogService } from "@bitwarden/components"; @Component({ selector: "app-two-factor-recovery", @@ -14,7 +16,12 @@ export class TwoFactorRecoveryComponent { authed: boolean; twoFactorProviderType = TwoFactorProviderType; - constructor(private i18nService: I18nService) {} + constructor( + @Inject(DIALOG_DATA) protected data: any, + private i18nService: I18nService, + ) { + this.auth(data.response); + } auth(authResponse: any) { this.authed = true; @@ -52,4 +59,8 @@ export class TwoFactorRecoveryComponent { private processResponse(response: TwoFactorRecoverResponse) { this.code = this.formatString(response.code); } + + static open(dialogService: DialogService, config: DialogConfig) { + return dialogService.open(TwoFactorRecoveryComponent, config); + } } diff --git a/apps/web/src/app/auth/settings/two-factor-setup.component.html b/apps/web/src/app/auth/settings/two-factor-setup.component.html index 781b52f0f30..a20bb345664 100644 --- a/apps/web/src/app/auth/settings/two-factor-setup.component.html +++ b/apps/web/src/app/auth/settings/two-factor-setup.component.html @@ -81,7 +81,6 @@ - diff --git a/apps/web/src/app/auth/settings/two-factor-setup.component.ts b/apps/web/src/app/auth/settings/two-factor-setup.component.ts index 8e2e721576e..dc7871baf94 100644 --- a/apps/web/src/app/auth/settings/two-factor-setup.component.ts +++ b/apps/web/src/app/auth/settings/two-factor-setup.component.ts @@ -33,8 +33,6 @@ import { TwoFactorYubiKeyComponent } from "./two-factor-yubikey.component"; templateUrl: "two-factor-setup.component.html", }) export class TwoFactorSetupComponent implements OnInit, OnDestroy { - @ViewChild("recoveryTemplate", { read: ViewContainerRef, static: true }) - recoveryModalRef: ViewContainerRef; @ViewChild("authenticatorTemplate", { read: ViewContainerRef, static: true }) authenticatorModalRef: ViewContainerRef; @ViewChild("yubikeyTemplate", { read: ViewContainerRef, static: true }) @@ -211,8 +209,8 @@ export class TwoFactorSetupComponent implements OnInit, OnDestroy { async recoveryCode() { const result = await this.callTwoFactorVerifyDialog(-1 as TwoFactorProviderType); if (result) { - const recoverComp = await this.openModal(this.recoveryModalRef, TwoFactorRecoveryComponent); - recoverComp.auth(result); + const recoverComp = TwoFactorRecoveryComponent.open(this.dialogService, { data: result }); + await lastValueFrom(recoverComp.closed); } }