1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-03-12 13:39:14 +01:00

[PM-1935] Migrate vault lock screen to component library (#6237)

* Migrate vault lock screen to component library

* Remove unnecessary divs

* Remove card from trial

* Migrate to standalone component

* refactor to use AnonLayout

* revert login component

* migrate web component to bitSubmit

* remove class

* use inject

* update web pageTitle translation

* validate on submit, not on blur

---------

Co-authored-by: rr-bw <102181210+rr-bw@users.noreply.github.com>
This commit is contained in:
Oscar Hinton 2024-07-10 02:19:12 +02:00 committed by GitHub
parent a87b5adb80
commit 7dfef8991c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 78 additions and 78 deletions

View File

@ -1,66 +1,27 @@
<form #form (ngSubmit)="submit()" [appApiAction]="formPromise" class="container" ngNativeValidate> <form [bitSubmit]="submit" [formGroup]="formGroup">
<div class="row justify-content-md-center mt-5"> <bit-form-field>
<div class="col-5"> <bit-label>{{ "masterPass" | i18n }}</bit-label>
<p class="text-center mb-4">
<i class="bwi bwi-lock bwi-4x text-muted" aria-hidden="true"></i>
</p>
<p class="lead text-center mx-4 mb-4">{{ "yourVaultIsLocked" | i18n }}</p>
<div class="card d-block">
<div class="card-body">
<div class="form-group">
<label for="masterPassword">{{ "masterPass" | i18n }}</label>
<div class="d-flex">
<input <input
id="masterPassword" type="password"
type="{{ showPassword ? 'text' : 'password' }}" formControlName="masterPassword"
name="MasterPassword" bitInput
class="text-monospace form-control"
[(ngModel)]="masterPassword"
required
appAutofocus appAutofocus
appInputVerbatim name="masterPassword"
required
/> />
<button <button type="button" bitIconButton bitSuffix bitPasswordInputToggle></button>
type="button" <bit-hint>{{ "loggedInAsEmailOn" | i18n: email : webVaultHostname }}</bit-hint>
class="ml-1 btn btn-link" </bit-form-field>
appA11yTitle="{{ 'toggleVisibility' | i18n }}"
(click)="togglePassword()"
>
<i
class="bwi bwi-lg"
aria-hidden="true"
[ngClass]="{ 'bwi-eye': !showPassword, 'bwi-eye-slash': showPassword }"
></i>
</button>
</div>
<small class="text-muted form-text">
{{ "loggedInAsEmailOn" | i18n: email : webVaultHostname }}
</small>
</div>
<hr /> <hr />
<div class="d-flex">
<button <div class="tw-flex tw-gap-2">
type="submit" <button type="submit" bitButton bitFormButton buttonType="primary" block>
class="btn btn-primary btn-block btn-submit" <i class="bwi bwi-unlock" aria-hidden="true"></i>
[disabled]="form.loading" {{ "unlock" | i18n }}
>
<span> <i class="bwi bwi-unlock" aria-hidden="true"></i> {{ "unlock" | i18n }} </span>
<i
class="bwi bwi-spinner bwi-spin"
title="{{ 'loading' | i18n }}"
aria-hidden="true"
></i>
</button> </button>
<button <button type="button" bitButton bitFormButton block (click)="logOut()">
type="button"
class="btn btn-outline-secondary btn-block ml-2 mt-0"
(click)="logOut()"
>
{{ "logOut" | i18n }} {{ "logOut" | i18n }}
</button> </button>
</div> </div>
</div>
</div>
</div>
</div>
</form> </form>

View File

@ -1,18 +1,49 @@
import { Component } from "@angular/core"; import { Component, inject } from "@angular/core";
import { FormBuilder, Validators } from "@angular/forms";
import { LockComponent as BaseLockComponent } from "@bitwarden/angular/auth/components/lock.component"; import { LockComponent as BaseLockComponent } from "@bitwarden/angular/auth/components/lock.component";
import { SharedModule } from "../shared";
@Component({ @Component({
selector: "app-lock", selector: "app-lock",
templateUrl: "lock.component.html", templateUrl: "lock.component.html",
standalone: true,
imports: [SharedModule],
}) })
export class LockComponent extends BaseLockComponent { export class LockComponent extends BaseLockComponent {
formBuilder = inject(FormBuilder);
formGroup = this.formBuilder.group({
masterPassword: ["", { validators: Validators.required, updateOn: "submit" }],
});
get masterPasswordFormControl() {
return this.formGroup.controls.masterPassword;
}
async ngOnInit() { async ngOnInit() {
await super.ngOnInit(); await super.ngOnInit();
this.masterPasswordFormControl.setValue(this.masterPassword);
this.onSuccessfulSubmit = async () => { this.onSuccessfulSubmit = async () => {
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. await this.router.navigateByUrl(this.successRoute);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.router.navigateByUrl(this.successRoute);
}; };
} }
async superSubmit() {
await super.submit();
}
submit = async () => {
this.formGroup.markAllAsTouched();
if (this.formGroup.invalid) {
return;
}
this.masterPassword = this.masterPasswordFormControl.value;
await this.superSubmit();
};
} }

View File

@ -17,6 +17,7 @@ import {
RegistrationStartComponent, RegistrationStartComponent,
RegistrationStartSecondaryComponent, RegistrationStartSecondaryComponent,
RegistrationStartSecondaryComponentData, RegistrationStartSecondaryComponentData,
LockIcon,
} from "@bitwarden/auth/angular"; } from "@bitwarden/auth/angular";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum"; import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
@ -113,11 +114,6 @@ const routes: Routes = [
component: SetPasswordComponent, component: SetPasswordComponent,
data: { titleId: "setMasterPassword" } satisfies DataProperties, data: { titleId: "setMasterPassword" } satisfies DataProperties,
}, },
{
path: "lock",
component: LockComponent,
canActivate: [deepLinkGuard(), lockGuard()],
},
{ path: "verify-email", component: VerifyEmailTokenComponent }, { path: "verify-email", component: VerifyEmailTokenComponent },
{ {
path: "accept-organization", path: "accept-organization",
@ -246,6 +242,21 @@ const routes: Routes = [
pageTitle: "logIn", pageTitle: "logIn",
}, },
}, },
{
path: "lock",
canActivate: [deepLinkGuard(), lockGuard()],
children: [
{
path: "",
component: LockComponent,
},
],
data: {
pageTitle: "yourVaultIsLockedV2",
pageIcon: LockIcon,
showReadonlyHostname: true,
} satisfies AnonLayoutWrapperData,
},
{ {
path: "2fa", path: "2fa",
canActivate: [unauthGuardFn()], canActivate: [unauthGuardFn()],

View File

@ -22,7 +22,6 @@ import { VerifyRecoverDeleteProviderComponent } from "../admin-console/providers
import { SponsoredFamiliesComponent } from "../admin-console/settings/sponsored-families.component"; import { SponsoredFamiliesComponent } from "../admin-console/settings/sponsored-families.component";
import { SponsoringOrgRowComponent } from "../admin-console/settings/sponsoring-org-row.component"; import { SponsoringOrgRowComponent } from "../admin-console/settings/sponsoring-org-row.component";
import { HintComponent } from "../auth/hint.component"; import { HintComponent } from "../auth/hint.component";
import { LockComponent } from "../auth/lock.component";
import { RecoverDeleteComponent } from "../auth/recover-delete.component"; import { RecoverDeleteComponent } from "../auth/recover-delete.component";
import { RecoverTwoFactorComponent } from "../auth/recover-two-factor.component"; import { RecoverTwoFactorComponent } from "../auth/recover-two-factor.component";
import { RegisterFormModule } from "../auth/register-form/register-form.module"; import { RegisterFormModule } from "../auth/register-form/register-form.module";
@ -141,7 +140,6 @@ import { SharedModule } from "./shared.module";
FolderAddEditComponent, FolderAddEditComponent,
FrontendLayoutComponent, FrontendLayoutComponent,
HintComponent, HintComponent,
LockComponent,
OrgAddEditComponent, OrgAddEditComponent,
OrgAttachmentsComponent, OrgAttachmentsComponent,
OrgCollectionsComponent, OrgCollectionsComponent,
@ -213,7 +211,6 @@ import { SharedModule } from "./shared.module";
FolderAddEditComponent, FolderAddEditComponent,
FrontendLayoutComponent, FrontendLayoutComponent,
HintComponent, HintComponent,
LockComponent,
OrgAddEditComponent, OrgAddEditComponent,
OrganizationLayoutComponent, OrganizationLayoutComponent,
OrgAttachmentsComponent, OrgAttachmentsComponent,

View File

@ -854,8 +854,8 @@
"emailAddress": { "emailAddress": {
"message": "Email address" "message": "Email address"
}, },
"yourVaultIsLocked": { "yourVaultIsLockedV2": {
"message": "Your vault is locked. Verify your master password to continue." "message": "Your vault is locked."
}, },
"uuid":{ "uuid":{
"message" : "UUID" "message" : "UUID"