From a72d6aed629dd3ac1e41adabc699d3c85377f69e Mon Sep 17 00:00:00 2001 From: sua yoo Date: Wed, 11 Oct 2023 13:26:24 -0700 Subject: [PATCH] add to reset form --- frontend/src/components/sign-up-form.ts | 24 +++++------ frontend/src/pages/join.ts | 4 +- frontend/src/pages/log-in.ts | 6 +-- frontend/src/pages/reset-password.ts | 54 ++++++++++++++++++++++--- frontend/src/pages/sign-up.ts | 4 +- 5 files changed, 67 insertions(+), 25 deletions(-) diff --git a/frontend/src/components/sign-up-form.ts b/frontend/src/components/sign-up-form.ts index 836c9a81dd..98fda655d7 100644 --- a/frontend/src/components/sign-up-form.ts +++ b/frontend/src/components/sign-up-form.ts @@ -105,7 +105,7 @@ export class SignUpForm extends LiteElement {

${msg( - "Your full name, or another name that org collaborators will see." + "Your full name, nickname, or another name that org collaborators can see." )}

@@ -124,7 +124,7 @@ export class SignUpForm extends LiteElement {

${msg( - str`Choose a strong password between ${PASSWORD_MINLENGTH} and ${PASSWORD_MAXLENGTH} characters.` + str`Choose a strong password between ${PASSWORD_MINLENGTH}-${PASSWORD_MAXLENGTH} characters.` )}

${when(this.pwStrengthResults, this.renderPasswordStrength)} @@ -145,17 +145,15 @@ export class SignUpForm extends LiteElement { `; } - private renderPasswordStrength = () => { - return html` -
- - -
- `; - }; + private renderPasswordStrength = () => html` +
+ + +
+ `; private onPasswordInput = debounce(150)(async (e: InputEvent) => { const { value } = e.target as BtrixInput; diff --git a/frontend/src/pages/join.ts b/frontend/src/pages/join.ts index 82ccbdb804..b3b80ced72 100644 --- a/frontend/src/pages/join.ts +++ b/frontend/src/pages/join.ts @@ -67,7 +67,7 @@ export class Join extends LiteElement {

${msg( - html`You've been invited to join + html`You’ve been invited to join ${hasInviteInfo ? this.inviteInfo.orgName || msg("Browsertrix Cloud") @@ -78,7 +78,7 @@ export class Join extends LiteElement {

+
${successMessage} -
+
${form}
${link}
@@ -284,7 +284,7 @@ export class LogInPage extends LiteElement { ?loading=${this.formState.value === "signingIn"} ?disabled=${this.formState.value === "backendInitializing"} type="submit" - >${msg("Log in")}${msg("Log In")} ${this.formState.value === "backendInitializing" ? html`
diff --git a/frontend/src/pages/reset-password.ts b/frontend/src/pages/reset-password.ts index 875862ce55..6281c0f377 100644 --- a/frontend/src/pages/reset-password.ts +++ b/frontend/src/pages/reset-password.ts @@ -1,20 +1,36 @@ import { state, property } from "lit/decorators.js"; -import { msg, localized } from "@lit/localize"; +import { str, msg, localized } from "@lit/localize"; +import debounce from "lodash/fp/debounce"; +import { when } from "lit/directives/when.js"; +import type { ZxcvbnResult } from "@zxcvbn-ts/core"; import type { ViewState } from "../utils/APIRouter"; import LiteElement, { html } from "../utils/LiteElement"; +import PasswordService from "../utils/PasswordService"; +import type { Input as BtrixInput } from "../components/input/input"; + +const PASSWORD_MINLENGTH = 8; +const PASSWORD_MAXLENGTH = 64; +const PASSWORD_MIN_SCORE = 3; @localized() export class ResetPassword extends LiteElement { @property({ type: Object }) viewState!: ViewState; + @state() + private pwStrengthResults: null | ZxcvbnResult = null; + @state() private serverError?: string; @state() private isSubmitting: boolean = false; + protected firstUpdated() { + PasswordService.setOptions(); + } + render() { let formError; @@ -29,22 +45,29 @@ export class ResetPassword extends LiteElement { } return html` -
-
+
+
+

+ ${msg( + str`Choose a strong password between ${PASSWORD_MINLENGTH}-${PASSWORD_MAXLENGTH} characters.` + )} +

+ ${when(this.pwStrengthResults, this.renderPasswordStrength)}
${formError} @@ -53,8 +76,10 @@ export class ResetPassword extends LiteElement { class="w-full" variant="primary" ?loading=${this.isSubmitting} + ?disabled=${!this.pwStrengthResults || + this.pwStrengthResults.score < PASSWORD_MIN_SCORE} type="submit" - >${msg("Change password")}${msg("Change Password")}
@@ -71,6 +96,25 @@ export class ResetPassword extends LiteElement { `; } + private renderPasswordStrength = () => html` +
+ + +
+ `; + + private onPasswordInput = debounce(150)(async (e: InputEvent) => { + const { value } = e.target as BtrixInput; + if (!value || value.length < 4) { + this.pwStrengthResults = null; + return; + } + this.pwStrengthResults = await PasswordService.checkStrength(value); + }) as any; + async onSubmit(event: SubmitEvent) { event.preventDefault(); this.isSubmitting = true; diff --git a/frontend/src/pages/sign-up.ts b/frontend/src/pages/sign-up.ts index 3735d68419..51870d436c 100644 --- a/frontend/src/pages/sign-up.ts +++ b/frontend/src/pages/sign-up.ts @@ -15,8 +15,8 @@ export class SignUp extends LiteElement { render() { return html` -
-
+
+
${this.isSignedUpWithoutAuth ? html`