From dcee01d09fb708f9b2b760478407240e510d7f22 Mon Sep 17 00:00:00 2001 From: Max Peintner Date: Tue, 19 Nov 2024 15:57:40 +0100 Subject: [PATCH] cleanup register, check for allowed methods --- apps/login/locales/de.json | 8 +++ apps/login/locales/en.json | 8 +++ apps/login/locales/es.json | 8 +++ apps/login/locales/it.json | 8 +++ apps/login/src/app/(login)/register/page.tsx | 32 ++++----- .../app/(login)/register/password/page.tsx | 70 +++++++++++++++++++ .../register-form-without-password.tsx | 31 +++++--- 7 files changed, 135 insertions(+), 30 deletions(-) create mode 100644 apps/login/src/app/(login)/register/password/page.tsx diff --git a/apps/login/locales/de.json b/apps/login/locales/de.json index c6576de0001..62691051a95 100644 --- a/apps/login/locales/de.json +++ b/apps/login/locales/de.json @@ -122,6 +122,14 @@ } }, "register": { + "disabled": { + "title": "Registrierung deaktiviert", + "description": "Die Registrierung ist deaktiviert. Bitte wenden Sie sich an den Administrator." + }, + "missingdata": { + "title": "Registrierung fehlgeschlagen", + "description": "Einige Daten fehlen. Bitte überprüfen Sie Ihre Eingaben." + }, "title": "Registrieren", "description": "Erstellen Sie Ihr ZITADEL-Konto.", "selectMethod": "Wählen Sie die Methode, mit der Sie sich authentifizieren möchten", diff --git a/apps/login/locales/en.json b/apps/login/locales/en.json index 4bb7bfe5524..68fa95e8102 100644 --- a/apps/login/locales/en.json +++ b/apps/login/locales/en.json @@ -122,6 +122,14 @@ } }, "register": { + "disabled": { + "title": "Registration disabled", + "description": "The registration is disabled. Please contact your administrator." + }, + "missingdata": { + "title": "Missing data", + "description": "Provide email, first and last name to register." + }, "title": "Register", "description": "Create your ZITADEL account.", "selectMethod": "Select the method you would like to authenticate", diff --git a/apps/login/locales/es.json b/apps/login/locales/es.json index e7f093dc5da..4b658bbdd06 100644 --- a/apps/login/locales/es.json +++ b/apps/login/locales/es.json @@ -122,6 +122,14 @@ } }, "register": { + "disabled": { + "title": "Registro deshabilitado", + "description": "Registrarse está deshabilitado en este momento." + }, + "missingdata": { + "title": "Datos faltantes", + "description": "No se proporcionaron datos suficientes para el registro." + }, "title": "Registrarse", "description": "Crea tu cuenta ZITADEL.", "selectMethod": "Selecciona el método con el que deseas autenticarte", diff --git a/apps/login/locales/it.json b/apps/login/locales/it.json index 0b488e00a27..2e6a7686b25 100644 --- a/apps/login/locales/it.json +++ b/apps/login/locales/it.json @@ -122,6 +122,14 @@ } }, "register": { + "disabled": { + "title": "Registration disabled", + "description": "Registrazione disabilitata. Contatta l'amministratore di sistema per assistenza." + }, + "missingdata": { + "title": "Registrazione", + "description": "Inserisci i tuoi dati per registrarti." + }, "title": "Registrati", "description": "Crea il tuo account ZITADEL.", "selectMethod": "Seleziona il metodo con cui desideri autenticarti", diff --git a/apps/login/src/app/(login)/register/page.tsx b/apps/login/src/app/(login)/register/page.tsx index f23582ae3f7..06cb928d9ad 100644 --- a/apps/login/src/app/(login)/register/page.tsx +++ b/apps/login/src/app/(login)/register/page.tsx @@ -1,10 +1,10 @@ import { DynamicTheme } from "@/components/dynamic-theme"; import { RegisterFormWithoutPassword } from "@/components/register-form-without-password"; -import { SetRegisterPasswordForm } from "@/components/set-register-password-form"; import { getBrandingSettings, getDefaultOrg, getLegalAndSupportSettings, + getLoginSettings, getPasswordComplexitySettings, } from "@/lib/zitadel"; import { Organization } from "@zitadel/proto/zitadel/org/v2/org_pb"; @@ -36,25 +36,18 @@ export default async function Page({ const branding = await getBrandingSettings(organization); - return setPassword ? ( - -
-

{t("password.title")}

-

{t("description")}

+ const loginSettings = await getLoginSettings(organization); - {legal && passwordComplexitySettings && ( - - )} -
-
- ) : ( + if (!loginSettings?.allowRegister) { + return ( + +
{t("disabled.title")}
+

{t("disabled.description")}

+
+ ); + } + + return (

{t("title")}

@@ -68,6 +61,7 @@ export default async function Page({ lastname={lastname} email={email} authRequestId={authRequestId} + loginSettings={loginSettings} > )}
diff --git a/apps/login/src/app/(login)/register/password/page.tsx b/apps/login/src/app/(login)/register/password/page.tsx new file mode 100644 index 00000000000..66843d45ac4 --- /dev/null +++ b/apps/login/src/app/(login)/register/password/page.tsx @@ -0,0 +1,70 @@ +import { DynamicTheme } from "@/components/dynamic-theme"; +import { SetRegisterPasswordForm } from "@/components/set-register-password-form"; +import { + getBrandingSettings, + getDefaultOrg, + getLegalAndSupportSettings, + getLoginSettings, + getPasswordComplexitySettings, +} from "@/lib/zitadel"; +import { Organization } from "@zitadel/proto/zitadel/org/v2/org_pb"; +import { getLocale, getTranslations } from "next-intl/server"; + +export default async function Page({ + searchParams, +}: { + searchParams: Record; +}) { + const locale = getLocale(); + const t = await getTranslations({ locale, namespace: "register" }); + + let { firstname, lastname, email, organization, authRequestId } = + searchParams; + + if (!organization) { + const org: Organization | null = await getDefaultOrg(); + if (org) { + organization = org.id; + } + } + + const missingData = !firstname || !lastname || !email; + + const legal = await getLegalAndSupportSettings(organization); + const passwordComplexitySettings = + await getPasswordComplexitySettings(organization); + + const branding = await getBrandingSettings(organization); + + const loginSettings = await getLoginSettings(organization); + + return missingData ? ( + +
{t("missingdata.title")}
+

{t("missingdata.description")}

+
+ ) : loginSettings?.allowRegister && loginSettings.allowUsernamePassword ? ( + +
+

{t("password.title")}

+

{t("description")}

+ + {legal && passwordComplexitySettings && ( + + )} +
+
+ ) : ( + +
{t("disabled.title")}
+

{t("disabled.description")}

+
+ ); +} diff --git a/apps/login/src/components/register-form-without-password.tsx b/apps/login/src/components/register-form-without-password.tsx index 52b6c3b9a4e..8392c9e903a 100644 --- a/apps/login/src/components/register-form-without-password.tsx +++ b/apps/login/src/components/register-form-without-password.tsx @@ -2,6 +2,10 @@ import { registerUser } from "@/lib/server/register"; import { LegalAndSupportSettings } from "@zitadel/proto/zitadel/settings/v2/legal_settings_pb"; +import { + LoginSettings, + PasskeysType, +} from "@zitadel/proto/zitadel/settings/v2/login_settings_pb"; import { useTranslations } from "next-intl"; import { useRouter } from "next/navigation"; import { useState } from "react"; @@ -32,6 +36,7 @@ type Props = { email?: string; organization?: string; authRequestId?: string; + loginSettings?: LoginSettings; }; export function RegisterFormWithoutPassword({ @@ -41,6 +46,7 @@ export function RegisterFormWithoutPassword({ lastname, organization, authRequestId, + loginSettings, }: Props) { const t = useTranslations("register"); @@ -99,7 +105,9 @@ export function RegisterFormWithoutPassword({ } if (withPassword) { - return router.push(`/register?` + new URLSearchParams(registerParams)); + return router.push( + `/register/password?` + new URLSearchParams(registerParams), + ); } else { return submitAndRegister(value); } @@ -143,29 +151,30 @@ export function RegisterFormWithoutPassword({ /> - {legal && ( )} -

{t("selectMethod")}

- -
- -
+ {/* show chooser if both methods are allowed */} + {loginSettings && + loginSettings.allowUsernamePassword && + loginSettings.passkeysType === PasskeysType.ALLOWED && ( +
+ +
+ )} {error && (
{error}
)} -