Validate postnumbers on the register route
This commit is contained in:
@@ -82,8 +82,7 @@ pub(super) async fn validate_registration_username(
|
|||||||
user_agent,
|
user_agent,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.await
|
.await?;
|
||||||
.map_err(InternalError::from_anyhow)?;
|
|
||||||
|
|
||||||
for violation in res.violations {
|
for violation in res.violations {
|
||||||
match violation.field.as_deref() {
|
match violation.field.as_deref() {
|
||||||
@@ -127,7 +126,10 @@ pub(super) async fn validate_registration_username(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
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);
|
state.add_error_on_form(FormError::Internal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,18 +142,19 @@ async fn render(
|
|||||||
locale: mas_i18n::DataLocale,
|
locale: mas_i18n::DataLocale,
|
||||||
mut ctx: RegisterContext,
|
mut ctx: RegisterContext,
|
||||||
action: OptionalPostAuthAction,
|
action: OptionalPostAuthAction,
|
||||||
mut repo: &mut BoxRepository,
|
csrf_token: impl ToString,
|
||||||
|
repo: &mut BoxRepository,
|
||||||
templates: &Templates,
|
templates: &Templates,
|
||||||
) -> Result<String, InternalError> {
|
) -> Result<String, InternalError> {
|
||||||
let post_action = action
|
let post_action = action
|
||||||
.load_context(&mut repo)
|
.load_context(repo)
|
||||||
.await
|
.await
|
||||||
.map_err(InternalError::from_anyhow)?;
|
.map_err(InternalError::from_anyhow)?;
|
||||||
if let Some(action) = post_action {
|
if let Some(action) = post_action {
|
||||||
ctx = ctx.with_post_action(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)]
|
#[tracing::instrument(name = "handlers.views.register.get", skip_all)]
|
||||||
@@ -211,8 +214,9 @@ pub(crate) async fn get(
|
|||||||
|
|
||||||
let content = render(
|
let content = render(
|
||||||
locale,
|
locale,
|
||||||
RegisterContext::new(providers).with_csrf(csrf_token.form_value()).inner,
|
RegisterContext::new(providers),
|
||||||
query,
|
query,
|
||||||
|
csrf_token.form_value(),
|
||||||
&mut repo,
|
&mut repo,
|
||||||
&templates,
|
&templates,
|
||||||
)
|
)
|
||||||
@@ -267,11 +271,9 @@ pub(crate) async fn post(
|
|||||||
if !state.is_valid() {
|
if !state.is_valid() {
|
||||||
let content = render(
|
let content = render(
|
||||||
locale,
|
locale,
|
||||||
RegisterContext::new(providers)
|
RegisterContext::new(providers).with_form_state(state),
|
||||||
.with_form_state(state)
|
|
||||||
.with_csrf(csrf_token.form_value())
|
|
||||||
.inner,
|
|
||||||
form.action,
|
form.action,
|
||||||
|
csrf_token.form_value(),
|
||||||
&mut repo,
|
&mut repo,
|
||||||
&templates,
|
&templates,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ use mas_router::UrlBuilder;
|
|||||||
use mas_storage::{
|
use mas_storage::{
|
||||||
BoxRepository, RepositoryAccess,
|
BoxRepository, RepositoryAccess,
|
||||||
queue::{QueueJobRepositoryExt as _, SendEmailAuthenticationCodeJob},
|
queue::{QueueJobRepositoryExt as _, SendEmailAuthenticationCodeJob},
|
||||||
user::{UserEmailRepository, UserRepository},
|
user::UserEmailRepository,
|
||||||
};
|
};
|
||||||
use mas_templates::{
|
use mas_templates::{
|
||||||
FieldError, FormError, FormState, PasswordRegisterContext, RegisterFormField, TemplateContext,
|
FieldError, FormError, FormState, PasswordRegisterContext, RegisterFormField, TemplateContext,
|
||||||
|
|||||||
Reference in New Issue
Block a user