1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-12 06:13:38 +00:00

migrate weak passwords report component

This commit is contained in:
jaasen-livefront
2024-07-09 14:15:19 -07:00
parent e8e9b01997
commit 0e453aafc1
2 changed files with 34 additions and 28 deletions

View File

@@ -2,26 +2,17 @@
<bit-container> <bit-container>
<p>{{ "breachDesc" | i18n }}</p> <p>{{ "breachDesc" | i18n }}</p>
<form #form (ngSubmit)="submit()" [appApiAction]="formPromise" ngNativeValidate> <form [bitSubmit]="submit" [formGroup]="formGroup">
<div class="row"> <bit-form-field class="tw-w-1/2">
<div class="form-group col-6"> <bit-label>{{ "username" | i18n }}</bit-label>
<label for="username">{{ "username" | i18n }}</label> <input id="username" type="email" formControlName="username" bitInput />
<input </bit-form-field>
id="username" <small class="form-text text-muted tw-mb-1">{{ "breachCheckUsernameEmail" | i18n }}</small>
type="text" <button type="submit" buttonType="primary" bitButton [loading]="loading">
name="Username"
class="form-control"
[(ngModel)]="username"
required
/>
<small class="form-text text-muted">{{ "breachCheckUsernameEmail" | i18n }}</small>
</div>
</div>
<button type="submit" buttonType="primary" bitButton [loading]="form.loading">
{{ "checkBreaches" | i18n }} {{ "checkBreaches" | i18n }}
</button> </button>
</form> </form>
<div class="mt-4" *ngIf="!form.loading && checkedUsername"> <div class="mt-4" *ngIf="checkedUsername">
<p *ngIf="error">{{ "reportError" | i18n }}...</p> <p *ngIf="error">{{ "reportError" | i18n }}...</p>
<ng-container *ngIf="!error"> <ng-container *ngIf="!error">
<app-callout type="success" title="{{ 'goodNews' | i18n }}" *ngIf="!breachedAccounts.length"> <app-callout type="success" title="{{ 'goodNews' | i18n }}" *ngIf="!breachedAccounts.length">

View File

@@ -1,4 +1,5 @@
import { Component, OnInit } from "@angular/core"; import { Component, OnInit } from "@angular/core";
import { FormBuilder, Validators } from "@angular/forms";
import { firstValueFrom, map } from "rxjs"; import { firstValueFrom, map } from "rxjs";
import { AuditService } from "@bitwarden/common/abstractions/audit.service"; 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", templateUrl: "breach-report.component.html",
}) })
export class BreachReportComponent implements OnInit { export class BreachReportComponent implements OnInit {
loading = false;
error = false; error = false;
username: string;
checkedUsername: string; checkedUsername: string;
breachedAccounts: BreachAccountResponse[] = []; breachedAccounts: BreachAccountResponse[] = [];
formPromise: Promise<BreachAccountResponse[]>; formGroup = this.formBuilder.group({
username: ["", { validators: [Validators.required, Validators.email], updateOn: "change" }],
});
constructor( constructor(
private auditService: AuditService, private auditService: AuditService,
private accountService: AccountService, private accountService: AccountService,
private formBuilder: FormBuilder,
) {} ) {}
async ngOnInit() { async ngOnInit() {
this.username = await firstValueFrom( this.formGroup
this.accountService.activeAccount$.pipe(map((a) => a?.email)), .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.error = false;
this.username = this.username.toLowerCase(); this.loading = true;
const username = this.formGroup.value.username;
try { try {
this.formPromise = this.auditService.breachedAccounts(this.username); this.breachedAccounts = await this.auditService.breachedAccounts(username);
this.breachedAccounts = await this.formPromise;
} catch { } catch {
this.error = true; this.error = true;
} finally {
this.loading = false;
} }
this.checkedUsername = this.username;
} this.checkedUsername = username;
};
} }