1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 00:03:56 +00:00

PM-2058 Update Two Factor Recovery Dialog (#8985)

This commit is contained in:
KiruthigaManivannan
2024-05-23 20:47:11 +05:30
committed by GitHub
parent 8335d8f484
commit 02c524dd5f
4 changed files with 38 additions and 46 deletions

View File

@@ -1,39 +1,23 @@
<div class="modal fade" role="dialog" aria-modal="true" aria-labelledby="2faRecoveryTitle"> <bit-dialog dialogSize="default">
<div class="modal-dialog" role="document"> <span bitDialogTitle>
<div class="modal-content"> {{ "twoStepLogin" | i18n }}
<div class="modal-header"> <span bitTypography="body1">{{ "recoveryCodeTitle" | i18n }}</span>
<h1 class="modal-title" id="2faRecoveryTitle"> </span>
{{ "twoStepLogin" | i18n }} <ng-container *ngIf="authed" bitDialogContent>
<small>{{ "recoveryCodeTitle" | i18n }}</small> <ng-container *ngIf="code">
</h1> <p bitTypography="body1" class="tw-text-center">{{ "twoFactorRecoveryYourCode" | i18n }}:</p>
<button <code class="tw-text-lg tw-w-full tw-flex tw-justify-center">{{ code }}</code>
type="button" </ng-container>
class="close" <ng-container *ngIf="!code">
data-dismiss="modal" {{ "twoFactorRecoveryNoCode" | i18n }}
appA11yTitle="{{ 'close' | i18n }}" </ng-container>
> </ng-container>
<span aria-hidden="true">&times;</span> <ng-container bitDialogFooter>
</button> <button bitButton type="button" buttonType="primary" (click)="print()" *ngIf="code">
</div> {{ "printCode" | i18n }}
<ng-container *ngIf="authed"> </button>
<div class="modal-body text-center"> <button bitButton type="button" buttonType="secondary" bitDialogClose>
<ng-container *ngIf="code"> {{ "close" | i18n }}
<p>{{ "twoFactorRecoveryYourCode" | i18n }}:</p> </button>
<code class="text-lg">{{ code }}</code> </ng-container>
</ng-container> </bit-dialog>
<ng-container *ngIf="!code">
{{ "twoFactorRecoveryNoCode" | i18n }}
</ng-container>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" (click)="print()" *ngIf="code">
{{ "printCode" | i18n }}
</button>
<button type="button" class="btn btn-outline-secondary" data-dismiss="modal">
{{ "close" | i18n }}
</button>
</div>
</ng-container>
</div>
</div>
</div>

View File

@@ -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 { TwoFactorProviderType } from "@bitwarden/common/auth/enums/two-factor-provider-type";
import { TwoFactorRecoverResponse } from "@bitwarden/common/auth/models/response/two-factor-recover.response"; import { TwoFactorRecoverResponse } from "@bitwarden/common/auth/models/response/two-factor-recover.response";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { DialogService } from "@bitwarden/components";
@Component({ @Component({
selector: "app-two-factor-recovery", selector: "app-two-factor-recovery",
@@ -14,7 +16,12 @@ export class TwoFactorRecoveryComponent {
authed: boolean; authed: boolean;
twoFactorProviderType = TwoFactorProviderType; twoFactorProviderType = TwoFactorProviderType;
constructor(private i18nService: I18nService) {} constructor(
@Inject(DIALOG_DATA) protected data: any,
private i18nService: I18nService,
) {
this.auth(data.response);
}
auth(authResponse: any) { auth(authResponse: any) {
this.authed = true; this.authed = true;
@@ -52,4 +59,8 @@ export class TwoFactorRecoveryComponent {
private processResponse(response: TwoFactorRecoverResponse) { private processResponse(response: TwoFactorRecoverResponse) {
this.code = this.formatString(response.code); this.code = this.formatString(response.code);
} }
static open(dialogService: DialogService, config: DialogConfig<any>) {
return dialogService.open(TwoFactorRecoveryComponent, config);
}
} }

View File

@@ -81,7 +81,6 @@
</bit-container> </bit-container>
<ng-template #authenticatorTemplate></ng-template> <ng-template #authenticatorTemplate></ng-template>
<ng-template #recoveryTemplate></ng-template>
<ng-template #duoTemplate></ng-template> <ng-template #duoTemplate></ng-template>
<ng-template #emailTemplate></ng-template> <ng-template #emailTemplate></ng-template>
<ng-template #yubikeyTemplate></ng-template> <ng-template #yubikeyTemplate></ng-template>

View File

@@ -33,8 +33,6 @@ import { TwoFactorYubiKeyComponent } from "./two-factor-yubikey.component";
templateUrl: "two-factor-setup.component.html", templateUrl: "two-factor-setup.component.html",
}) })
export class TwoFactorSetupComponent implements OnInit, OnDestroy { export class TwoFactorSetupComponent implements OnInit, OnDestroy {
@ViewChild("recoveryTemplate", { read: ViewContainerRef, static: true })
recoveryModalRef: ViewContainerRef;
@ViewChild("authenticatorTemplate", { read: ViewContainerRef, static: true }) @ViewChild("authenticatorTemplate", { read: ViewContainerRef, static: true })
authenticatorModalRef: ViewContainerRef; authenticatorModalRef: ViewContainerRef;
@ViewChild("yubikeyTemplate", { read: ViewContainerRef, static: true }) @ViewChild("yubikeyTemplate", { read: ViewContainerRef, static: true })
@@ -211,8 +209,8 @@ export class TwoFactorSetupComponent implements OnInit, OnDestroy {
async recoveryCode() { async recoveryCode() {
const result = await this.callTwoFactorVerifyDialog(-1 as TwoFactorProviderType); const result = await this.callTwoFactorVerifyDialog(-1 as TwoFactorProviderType);
if (result) { if (result) {
const recoverComp = await this.openModal(this.recoveryModalRef, TwoFactorRecoveryComponent); const recoverComp = TwoFactorRecoveryComponent.open(this.dialogService, { data: result });
recoverComp.auth(result); await lastValueFrom(recoverComp.closed);
} }
} }