Keeps the same behavior as before when parameter is missing

This commit is contained in:
Greg Burri 2025-05-21 21:27:28 +02:00
parent 817ef3d727
commit 5a314ffbec
2 changed files with 27 additions and 1 deletions

View file

@ -110,6 +110,7 @@ pub async fn dev_panel(
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct LogsParams { pub struct LogsParams {
#[serde(default)]
pub log_file: String, pub log_file: String,
} }

View file

@ -1,4 +1,4 @@
use std::{collections::HashMap, net::SocketAddr, sync::Arc}; use std::{net::SocketAddr, sync::Arc};
use askama::Template; use askama::Template;
use axum::{ use axum::{
@ -33,6 +33,7 @@ const VALIDATION_TOKEN_KEY: &str = "validation_token";
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct ValidationTokenParams { pub struct ValidationTokenParams {
#[serde(default)]
validation_token: String, validation_token: String,
} }
@ -227,6 +228,15 @@ pub async fn sign_up_validation(
), ),
)); ));
} }
if params.validation_token.is_empty() {
warn!("Unable to validate: no token provided");
return Ok((
jar,
Html(MessageTemplate::new(context.tr.t(Sentence::ValidationError), context).render()?),
));
}
let (client_ip, client_user_agent) = utils::get_ip_and_user_agent(&headers, addr); let (client_ip, client_user_agent) = utils::get_ip_and_user_agent(&headers, addr);
match connection match connection
@ -556,6 +566,7 @@ pub async fn ask_reset_password_post(
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct ResetPasswordGetParams { pub struct ResetPasswordGetParams {
#[serde(default)]
reset_token: String, reset_token: String,
} }
@ -565,6 +576,13 @@ pub async fn reset_password_get(
Extension(context): Extension<Context>, Extension(context): Extension<Context>,
Query(params): Query<ResetPasswordGetParams>, Query(params): Query<ResetPasswordGetParams>,
) -> Result<Response> { ) -> Result<Response> {
if params.reset_token.is_empty() {
return Ok(Html(
MessageTemplate::new(context.tr.t(Sentence::AskResetTokenMissing), context).render()?,
)
.into_response());
}
// Check if the token is valid. // Check if the token is valid.
if connection if connection
.is_reset_password_token_valid( .is_reset_password_token_valid(
@ -954,6 +972,13 @@ pub async fn email_revalidation(
} }
let (client_ip, client_user_agent) = utils::get_ip_and_user_agent(&headers, addr); let (client_ip, client_user_agent) = utils::get_ip_and_user_agent(&headers, addr);
if params.validation_token.is_empty() {
return Ok((
jar,
Html(MessageTemplate::new(context.tr.t(Sentence::ValidationError), context).render()?),
));
}
match connection match connection
.validation( .validation(
&params.validation_token, &params.validation_token,