From 18259a641235161df95bf8878a26b1f96faa343c Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Fri, 3 Nov 2023 16:39:00 +0100 Subject: [PATCH] Fix the login template not rendering on policy error --- crates/templates/src/context.rs | 22 +++++++++++++++++++++- templates/components/field.html | 2 +- templates/pages/sso.html | 6 ++++-- translations/en.json | 8 ++++---- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/crates/templates/src/context.rs b/crates/templates/src/context.rs index 3c5a6933..f6ca8e89 100644 --- a/crates/templates/src/context.rs +++ b/crates/templates/src/context.rs @@ -32,7 +32,7 @@ use ulid::Ulid; use url::Url; pub use self::branding::SiteBranding; -use crate::{FormField, FormState}; +use crate::{FieldError, FormField, FormState}; /// Helper trait to construct context wrappers pub trait TemplateContext: Serialize { @@ -408,6 +408,26 @@ impl TemplateContext for LoginContext { password_disabled: false, providers: Vec::new(), }, + LoginContext { + form: FormState::default() + .with_error_on_field(LoginFormField::Username, FieldError::Required) + .with_error_on_field( + LoginFormField::Password, + FieldError::Policy { + message: "password too short".to_owned(), + }, + ), + next: None, + password_disabled: false, + providers: Vec::new(), + }, + LoginContext { + form: FormState::default() + .with_error_on_field(LoginFormField::Username, FieldError::Exists), + next: None, + password_disabled: false, + providers: Vec::new(), + }, ] } } diff --git a/templates/components/field.html b/templates/components/field.html index 66208022..1469ce70 100644 --- a/templates/components/field.html +++ b/templates/components/field.html @@ -72,7 +72,7 @@ limitations under the License. {% elif error.kind == "exists" and field.name == "username" %} {{ _("mas.errors.username_taken") }} {% elif error.kind == "policy" %} - {{ _("mas.errors.denied_policy", message=error.message) }} + {{ _("mas.errors.denied_policy", policy=error.message) }} {% else %} {{ error.kind }} {% endif %} diff --git a/templates/pages/sso.html b/templates/pages/sso.html index a7df3c94..119faed4 100644 --- a/templates/pages/sso.html +++ b/templates/pages/sso.html @@ -24,8 +24,10 @@ limitations under the License. {{ icon.web_browser() }} -

Allow access to your account?

-

{{ client_name }} wants to access your account. This will allow {{ client_name }} to:

+
+

Allow access to your account?

+

{{ client_name }} wants to access your account. This will allow {{ client_name }} to:

+