From 0e453aafc154fee48f37bb22a7f24cdf2847a43c Mon Sep 17 00:00:00 2001 From: jaasen-livefront Date: Tue, 9 Jul 2024 14:15:19 -0700 Subject: [PATCH] migrate weak passwords report component --- .../pages/breach-report.component.html | 25 ++++--------- .../reports/pages/breach-report.component.ts | 37 +++++++++++++------ 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/apps/web/src/app/tools/reports/pages/breach-report.component.html b/apps/web/src/app/tools/reports/pages/breach-report.component.html index 51191ddf2d..810daba081 100644 --- a/apps/web/src/app/tools/reports/pages/breach-report.component.html +++ b/apps/web/src/app/tools/reports/pages/breach-report.component.html @@ -2,26 +2,17 @@

{{ "breachDesc" | i18n }}

-
-
-
- - - {{ "breachCheckUsernameEmail" | i18n }} -
-
-
-
+

{{ "reportError" | i18n }}...

diff --git a/apps/web/src/app/tools/reports/pages/breach-report.component.ts b/apps/web/src/app/tools/reports/pages/breach-report.component.ts index 5728d36078..40c0cba830 100644 --- a/apps/web/src/app/tools/reports/pages/breach-report.component.ts +++ b/apps/web/src/app/tools/reports/pages/breach-report.component.ts @@ -1,4 +1,5 @@ import { Component, OnInit } from "@angular/core"; +import { FormBuilder, Validators } from "@angular/forms"; import { firstValueFrom, map } from "rxjs"; import { AuditService } from "@bitwarden/common/abstractions/audit.service"; @@ -10,32 +11,46 @@ import { BreachAccountResponse } from "@bitwarden/common/models/response/breach- templateUrl: "breach-report.component.html", }) export class BreachReportComponent implements OnInit { + loading = false; error = false; - username: string; checkedUsername: string; breachedAccounts: BreachAccountResponse[] = []; - formPromise: Promise; + formGroup = this.formBuilder.group({ + username: ["", { validators: [Validators.required, Validators.email], updateOn: "change" }], + }); constructor( private auditService: AuditService, private accountService: AccountService, + private formBuilder: FormBuilder, ) {} async ngOnInit() { - this.username = await firstValueFrom( - this.accountService.activeAccount$.pipe(map((a) => a?.email)), - ); + this.formGroup + .get("username") + .setValue( + await firstValueFrom(this.accountService.activeAccount$.pipe(map((a) => a?.email))), + ); } - async submit() { + submit = async () => { + this.formGroup.markAsTouched(); + + if (this.formGroup.invalid) { + return; + } + this.error = false; - this.username = this.username.toLowerCase(); + this.loading = true; + const username = this.formGroup.value.username; try { - this.formPromise = this.auditService.breachedAccounts(this.username); - this.breachedAccounts = await this.formPromise; + this.breachedAccounts = await this.auditService.breachedAccounts(username); } catch { this.error = true; + } finally { + this.loading = false; } - this.checkedUsername = this.username; - } + + this.checkedUsername = username; + }; }