From 6f9dc73e18b26db6189dea37744a6d1c0853bd1b Mon Sep 17 00:00:00 2001 From: Andreas Coroiu Date: Thu, 4 May 2023 13:47:48 +0200 Subject: [PATCH] [PM-2014] feat: implement mocked failing wizard flow --- .../create-credential-dialog.component.html | 51 ++++++++++++---- .../create-credential-dialog.component.ts | 61 ++++++++++++++++++- .../fido2-login-settings.module.ts | 3 +- apps/web/src/locales/en/messages.json | 6 ++ 4 files changed, 107 insertions(+), 14 deletions(-) diff --git a/apps/web/src/app/settings/fido2-login-settings/create-credential-dialog/create-credential-dialog.component.html b/apps/web/src/app/settings/fido2-login-settings/create-credential-dialog/create-credential-dialog.component.html index b11448778b..d4c57c7183 100644 --- a/apps/web/src/app/settings/fido2-login-settings/create-credential-dialog/create-credential-dialog.component.html +++ b/apps/web/src/app/settings/fido2-login-settings/create-credential-dialog/create-credential-dialog.component.html @@ -1,11 +1,40 @@ - - {{ "loginWithPasskey" | i18n }} - {{ "newPasskey" | i18n }} - - Enter you master password here - - - - - +
+ + {{ "loginWithPasskey" | i18n }} + {{ "newPasskey" | i18n }} + + + +

+ {{ "passkeyEnterMasterPassword" | i18n }} +

+ + {{ "masterPassword" | i18n }} + + + {{ "confirmIdentity" | i18n }} + +
+
+ + + + +
+
diff --git a/apps/web/src/app/settings/fido2-login-settings/create-credential-dialog/create-credential-dialog.component.ts b/apps/web/src/app/settings/fido2-login-settings/create-credential-dialog/create-credential-dialog.component.ts index 177c0b91bc..3740b9f52b 100644 --- a/apps/web/src/app/settings/fido2-login-settings/create-credential-dialog/create-credential-dialog.component.ts +++ b/apps/web/src/app/settings/fido2-login-settings/create-credential-dialog/create-credential-dialog.component.ts @@ -1,5 +1,6 @@ -import { DialogConfig } from "@angular/cdk/dialog"; +import { DialogConfig, DialogRef } from "@angular/cdk/dialog"; import { Component } from "@angular/core"; +import { FormBuilder, Validators } from "@angular/forms"; import { DialogService } from "@bitwarden/components"; @@ -8,10 +9,66 @@ export enum CreateCredentialDialogResult { Canceled, } +type Step = + | "userVerification" + | "credentialCreation" + | "credentialCreationFailed" + | "credentialNaming"; + @Component({ templateUrl: "create-credential-dialog.component.html", }) -export class CreateCredentialDialogComponent {} +export class CreateCredentialDialogComponent { + protected currentStep: Step = "userVerification"; + protected formGroup = this.formBuilder.group({ + userVerification: this.formBuilder.group({ + masterPassword: ["", [Validators.required]], + }), + credentialNaming: this.formBuilder.group({ + name: ["", Validators.maxLength(50)], + }), + }); + + constructor(private formBuilder: FormBuilder, private dialogRef: DialogRef) {} + + protected submit = async () => { + this.dialogRef.disableClose = true; + + try { + if (this.currentStep === "userVerification") { + this.formGroup.controls.userVerification.markAllAsTouched(); + if (this.formGroup.controls.userVerification.invalid) { + return; + } + await this.verifyUser(); + this.currentStep = "credentialCreation"; + } + + if (this.currentStep === "credentialCreationFailed") { + this.currentStep = "credentialCreation"; + } + + if (this.currentStep === "credentialCreation") { + try { + await this.createCredential(); + } catch { + this.currentStep = "credentialCreationFailed"; + } + } + } finally { + this.dialogRef.disableClose = false; + } + }; + + private async verifyUser() { + // Mocked + await new Promise((resolve) => setTimeout(resolve, 1000)); + } + + private async createCredential() { + await new Promise((_, reject) => setTimeout(() => reject(new Error("Not implemented")), 1000)); + } +} /** * Strongly typed helper to open a CreateCredentialDialog diff --git a/apps/web/src/app/settings/fido2-login-settings/fido2-login-settings.module.ts b/apps/web/src/app/settings/fido2-login-settings/fido2-login-settings.module.ts index a1c47571e8..76d6cb2341 100644 --- a/apps/web/src/app/settings/fido2-login-settings/fido2-login-settings.module.ts +++ b/apps/web/src/app/settings/fido2-login-settings/fido2-login-settings.module.ts @@ -1,4 +1,5 @@ import { NgModule } from "@angular/core"; +import { FormsModule, ReactiveFormsModule } from "@angular/forms"; import { SharedModule } from "../../shared/shared.module"; @@ -6,7 +7,7 @@ import { CreateCredentialDialogComponent } from "./create-credential-dialog/crea import { Fido2LoginSettingsComponent } from "./fido2-login-settings.component"; @NgModule({ - imports: [SharedModule], + imports: [SharedModule, FormsModule, ReactiveFormsModule], declarations: [Fido2LoginSettingsComponent, CreateCredentialDialogComponent], exports: [Fido2LoginSettingsComponent], }) diff --git a/apps/web/src/locales/en/messages.json b/apps/web/src/locales/en/messages.json index 9b959f3751..b4926ac744 100644 --- a/apps/web/src/locales/en/messages.json +++ b/apps/web/src/locales/en/messages.json @@ -640,6 +640,12 @@ "learnMoreAboutPasswordless": { "message": "Learn more about passwordless" }, + "passkeyEnterMasterPassword": { + "message": "Enter your master password to modify log in with passkey settings." + }, + "tryAgain": { + "message": "Try again" + }, "createAccount": { "message": "Create account" },