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

Commit 18259a6

Browse files
committed
Fix the login template not rendering on policy error
1 parent a2f8d81 commit 18259a6

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

crates/templates/src/context.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use ulid::Ulid;
3232
use url::Url;
3333

3434
pub use self::branding::SiteBranding;
35-
use crate::{FormField, FormState};
35+
use crate::{FieldError, FormField, FormState};
3636

3737
/// Helper trait to construct context wrappers
3838
pub trait TemplateContext: Serialize {
@@ -408,6 +408,26 @@ impl TemplateContext for LoginContext {
408408
password_disabled: false,
409409
providers: Vec::new(),
410410
},
411+
LoginContext {
412+
form: FormState::default()
413+
.with_error_on_field(LoginFormField::Username, FieldError::Required)
414+
.with_error_on_field(
415+
LoginFormField::Password,
416+
FieldError::Policy {
417+
message: "password too short".to_owned(),
418+
},
419+
),
420+
next: None,
421+
password_disabled: false,
422+
providers: Vec::new(),
423+
},
424+
LoginContext {
425+
form: FormState::default()
426+
.with_error_on_field(LoginFormField::Username, FieldError::Exists),
427+
next: None,
428+
password_disabled: false,
429+
providers: Vec::new(),
430+
},
411431
]
412432
}
413433
}

templates/components/field.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
{% elif error.kind == "exists" and field.name == "username" %}
7373
{{ _("mas.errors.username_taken") }}
7474
{% elif error.kind == "policy" %}
75-
{{ _("mas.errors.denied_policy", message=error.message) }}
75+
{{ _("mas.errors.denied_policy", policy=error.message) }}
7676
{% else %}
7777
{{ error.kind }}
7878
{% endif %}

templates/pages/sso.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
{{ icon.web_browser() }}
2525
</div>
2626

27-
<h1 class="title">Allow access to your account?</h1>
28-
<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>
27+
<div class="header">
28+
<h1 class="title">Allow access to your account?</h1>
29+
<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>
30+
</div>
2931
</header>
3032

3133
<section class="consent-scope-list">

translations/en.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
},
77
"continue": "Continue",
88
"@continue": {
9-
"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"
9+
"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"
1010
},
1111
"create_account": "Create Account",
1212
"@create_account": {
@@ -18,7 +18,7 @@
1818
},
1919
"sign_out": "Sign out",
2020
"@sign_out": {
21-
"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"
21+
"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"
2222
}
2323
},
2424
"app": {
@@ -167,7 +167,7 @@
167167
"errors": {
168168
"denied_policy": "Denied by policy: %(policy)s",
169169
"@denied_policy": {
170-
"context": "components/field.html:75:17-69"
170+
"context": "components/field.html:75:17-68"
171171
},
172172
"field_required": "This field is required",
173173
"@field_required": {
@@ -246,7 +246,7 @@
246246
},
247247
"not_you": "Not %(username)s?",
248248
"@not_you": {
249-
"context": "pages/consent.html:65:11-67, pages/sso.html:48:11-67",
249+
"context": "pages/consent.html:65:11-67, pages/sso.html:50:11-67",
250250
"description": "Suggestions for the user to log in as a different user"
251251
},
252252
"or_separator": "Or",

0 commit comments

Comments
 (0)