Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Commit

Permalink
Fix the login template not rendering on policy error
Browse files Browse the repository at this point in the history
  • Loading branch information
sandhose committed Nov 3, 2023
1 parent a2f8d81 commit 18259a6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
22 changes: 21 additions & 1 deletion crates/templates/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
},
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion templates/components/field.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
{% 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 %}
Expand Down
6 changes: 4 additions & 2 deletions templates/pages/sso.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
{{ icon.web_browser() }}
</div>

<h1 class="title">Allow access to your account?</h1>
<p class="text"><span class="whitespace-nowrap">{{ client_name }}</span> wants to access your account. This will allow <span class="whitespace-nowrap">{{ client_name }}</span> to:</p>
<div class="header">
<h1 class="title">Allow access to your account?</h1>
<p class="text"><span class="whitespace-nowrap">{{ client_name }}</span> wants to access your account. This will allow <span class="whitespace-nowrap">{{ client_name }}</span> to:</p>
</div>
</header>

<section class="consent-scope-list">
Expand Down
8 changes: 4 additions & 4 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"continue": "Continue",
"@continue": {
"context": "pages/account/emails/add.html:45:26-46, pages/account/emails/verify.html:60:26-46, pages/consent.html:60:28-48, pages/login.html:59:30-50, pages/reauth.html:40:28-48, pages/register.html:59:28-48, pages/sso.html:43:28-48"
"context": "pages/account/emails/add.html:45:26-46, pages/account/emails/verify.html:60:26-46, pages/consent.html:60:28-48, pages/login.html:59:30-50, pages/reauth.html:40:28-48, pages/register.html:59:28-48, pages/sso.html:45:28-48"
},
"create_account": "Create Account",
"@create_account": {
Expand All @@ -18,7 +18,7 @@
},
"sign_out": "Sign out",
"@sign_out": {
"context": "pages/consent.html:68:28-48, pages/index.html:36:28-48, pages/policy_violation.html:46:28-48, pages/sso.html:51:28-48, pages/upstream_oauth2/link_mismatch.html:32:24-44, pages/upstream_oauth2/suggest_link.html:40:26-46"
"context": "pages/consent.html:68:28-48, pages/index.html:36:28-48, pages/policy_violation.html:46:28-48, pages/sso.html:53:28-48, pages/upstream_oauth2/link_mismatch.html:32:24-44, pages/upstream_oauth2/suggest_link.html:40:26-46"
}
},
"app": {
Expand Down Expand Up @@ -167,7 +167,7 @@
"errors": {
"denied_policy": "Denied by policy: %(policy)s",
"@denied_policy": {
"context": "components/field.html:75:17-69"
"context": "components/field.html:75:17-68"
},
"field_required": "This field is required",
"@field_required": {
Expand Down Expand Up @@ -246,7 +246,7 @@
},
"not_you": "Not %(username)s?",
"@not_you": {
"context": "pages/consent.html:65:11-67, pages/sso.html:48:11-67",
"context": "pages/consent.html:65:11-67, pages/sso.html:50:11-67",
"description": "Suggestions for the user to log in as a different user"
},
"or_separator": "Or",
Expand Down

0 comments on commit 18259a6

Please sign in to comment.