/* This file is part of GNU Taler (C) 2022-2024 Taler Systems S.A. GNU Taler is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Taler; see the file COPYING. If not, see */ import { TranslatedString } from "@gnu-taler/taler-util"; import { createNewForm, notifyError, useTranslationContext, } from "@gnu-taler/web-util/browser"; import { VNode, h } from "preact"; import { usePreferences } from "../hooks/preferences.js"; export function CreateAccount({ onNewAccount, }: { onNewAccount: (password: string) => void; }): VNode { const { i18n } = useTranslationContext(); const Form = createNewForm<{ password: string; repeat: string; }>(); const [settings] = usePreferences(); return (

Create account

{ return { password: { error: !v.password ? i18n.str`required` : settings.allowInsecurePassword ? undefined : v.password.length < 8 ? i18n.str`should have at least 8 characters` : !v.password.match(/[a-z]/) && v.password.match(/[A-Z]/) ? i18n.str`should have lowercase and uppercase characters` : !v.password.match(/\d/) ? i18n.str`should have numbers` : !v.password.match(/[^a-zA-Z\d]/) ? i18n.str`should have at least one character which is not a number or letter` : undefined, }, repeat: { error: !v.repeat ? i18n.str`required` : v.repeat !== v.password ? i18n.str`doesn't match` : undefined, }, }; }} onSubmit={async (v, s) => { const error = s?.password?.error ?? s?.repeat?.error; if (error) { notifyError( i18n.str`Can't create account`, error as TranslatedString, ); } else { onNewAccount(v.password!); } }} >
); }