Validate postnumbers on the register route

This commit is contained in:
Letro Bot
2026-04-08 17:58:54 +03:30
parent def6fa6539
commit 2ff0e890ec
2 changed files with 14 additions and 12 deletions

View File

@@ -82,8 +82,7 @@ pub(super) async fn validate_registration_username(
user_agent,
},
})
.await
.map_err(InternalError::from_anyhow)?;
.await?;
for violation in res.violations {
match violation.field.as_deref() {
@@ -127,7 +126,10 @@ pub(super) async fn validate_registration_username(
);
}
Err(e) => {
tracing::error!(error = &e as &dyn std::error::Error, "postnumber resolver error");
tracing::error!(
error = &e as &dyn std::error::Error,
"postnumber resolver error"
);
state.add_error_on_form(FormError::Internal);
}
}
@@ -140,18 +142,19 @@ async fn render(
locale: mas_i18n::DataLocale,
mut ctx: RegisterContext,
action: OptionalPostAuthAction,
mut repo: &mut BoxRepository,
csrf_token: impl ToString,
repo: &mut BoxRepository,
templates: &Templates,
) -> Result<String, InternalError> {
let post_action = action
.load_context(&mut repo)
.load_context(repo)
.await
.map_err(InternalError::from_anyhow)?;
if let Some(action) = post_action {
ctx = ctx.with_post_action(action);
}
Ok(templates.render_register(&ctx.with_language(locale))?)
Ok(templates.render_register(&ctx.with_csrf(csrf_token).with_language(locale))?)
}
#[tracing::instrument(name = "handlers.views.register.get", skip_all)]
@@ -211,8 +214,9 @@ pub(crate) async fn get(
let content = render(
locale,
RegisterContext::new(providers).with_csrf(csrf_token.form_value()).inner,
RegisterContext::new(providers),
query,
csrf_token.form_value(),
&mut repo,
&templates,
)
@@ -267,11 +271,9 @@ pub(crate) async fn post(
if !state.is_valid() {
let content = render(
locale,
RegisterContext::new(providers)
.with_form_state(state)
.with_csrf(csrf_token.form_value())
.inner,
RegisterContext::new(providers).with_form_state(state),
form.action,
csrf_token.form_value(),
&mut repo,
&templates,
)

View File

@@ -26,7 +26,7 @@ use mas_router::UrlBuilder;
use mas_storage::{
BoxRepository, RepositoryAccess,
queue::{QueueJobRepositoryExt as _, SendEmailAuthenticationCodeJob},
user::{UserEmailRepository, UserRepository},
user::UserEmailRepository,
};
use mas_templates::{
FieldError, FormError, FormState, PasswordRegisterContext, RegisterFormField, TemplateContext,