Redirects: properly redirect to the current week

Previously, most redirects targeted the root of the application.
This was okay for the first part of development where only one week would be
active, but would be annoying when using multiple weeks.

Change those redirects to call week::week.

Change the login path to be dependant on the current week as well,
so it can be correctly redirected.
This commit is contained in:
trotFunky 2024-07-26 01:08:30 +01:00
parent e08a46af3a
commit a0b79a17ea
6 changed files with 22 additions and 22 deletions

View file

@ -6,7 +6,7 @@ use rocket_db_pools::{sqlx, Connection};
use pulldown_cmark::{Parser, Options};
use sqlx::Row;
use crate::{auth, database};
use crate::{auth, database, week};
#[derive(FromForm)]
pub struct TruthUpdateForm {
@ -20,7 +20,7 @@ pub async fn edit_truth(week: u8, truth_number: u8, form: Form<TruthUpdateForm>,
let user = auth::get_user(week, &mut db, cookies).await;
if !user.is_admin {
cookies.add(("toast_error", "Vous n'avez pas la permission de changer la vérité."));
return Redirect::to(uri!("/"));
return Redirect::to(uri!(week::week(week)));
}
let mut options = Options::empty();
@ -50,7 +50,7 @@ pub async fn edit_truth(week: u8, truth_number: u8, form: Form<TruthUpdateForm>,
}
};
Redirect::to(uri!("/"))
Redirect::to(uri!(week::week(week)))
}
#[post("/<week>/new_truth", data="<form>")]
@ -59,7 +59,7 @@ pub async fn create_truth(week: u8, form: Form<TruthUpdateForm>,
let user = auth::get_user(week, &mut db, cookies).await;
if !user.is_admin {
cookies.add(("toast_error", "Vous n'avez pas la permission d'ajouter de vérité."));
return Redirect::to(uri!("/"));
return Redirect::to(uri!(week::week(week)));
}
let truth_number: u8 = match sqlx::query("SELECT max(number) from Truths WHERE week == $1;")
@ -76,7 +76,7 @@ pub async fn create_truth(week: u8, form: Form<TruthUpdateForm>,
if truth_number == 0 {
error!("Error while getting max truth number.");
cookies.add(("toast_error", "Erreur lors de l'ajout de la vérité..."));
return Redirect::to(uri!("/"));
return Redirect::to(uri!(week::week(week)));
}
let mut options = Options::empty();
@ -108,5 +108,5 @@ pub async fn create_truth(week: u8, form: Form<TruthUpdateForm>,
debug!("Truth was successfully added");
Redirect::to(uri!("/"))
Redirect::to(uri!(week::week(week)))
}