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:
parent
e08a46af3a
commit
a0b79a17ea
6 changed files with 22 additions and 22 deletions
16
src/auth.rs
16
src/auth.rs
|
@ -9,7 +9,7 @@ use argon2::{Argon2, PasswordHash, PasswordVerifier};
|
|||
use blake2::{Blake2b512, Digest};
|
||||
use blake2::digest::FixedOutput;
|
||||
use crate::database_records::{AuthTokens, PlayerLoginInfo, Vote};
|
||||
use crate::database;
|
||||
use crate::{database, week};
|
||||
use database::Db;
|
||||
|
||||
// TODO: Make FromRequest guard https://api.rocket.rs/v0.5/rocket/request/trait.FromRequest and split admin
|
||||
|
@ -126,8 +126,8 @@ pub struct AuthForm {
|
|||
password: String
|
||||
}
|
||||
|
||||
#[post("/login", data="<form>")]
|
||||
pub async fn login(form: Form<AuthForm>, mut db: Connection<Db>, cookies: &CookieJar<'_>) -> Redirect {
|
||||
#[post("/<week>/login", data="<form>")]
|
||||
pub async fn login(week: u8, form: Form<AuthForm>, mut db: Connection<Db>, cookies: &CookieJar<'_>) -> Redirect {
|
||||
let user_search: Result<PlayerLoginInfo, _> = sqlx::query_as("SELECT id, is_admin, name, pwd_hash FROM Players WHERE name == $1")
|
||||
.bind(&form.name)
|
||||
.fetch_one(&mut **db)
|
||||
|
@ -136,7 +136,7 @@ pub async fn login(form: Form<AuthForm>, mut db: Connection<Db>, cookies: &Cooki
|
|||
if user_search.is_err() {
|
||||
error!("Login failed : invalid user {:?}, err: {:?}", form.name, user_search.err());
|
||||
cookies.add(("toast_error", "Impossible de se connecter !"));
|
||||
return Redirect::to(uri!("/"));
|
||||
return Redirect::to(uri!(week::week(week)));
|
||||
}
|
||||
let new_user = user_search.unwrap();
|
||||
|
||||
|
@ -144,7 +144,7 @@ pub async fn login(form: Form<AuthForm>, mut db: Connection<Db>, cookies: &Cooki
|
|||
if password_hash_parse.is_err() {
|
||||
error!("Login failed : could not parse password hash {:?}", password_hash_parse.err());
|
||||
cookies.add(("toast_error", "Impossible de se connecter !"));
|
||||
return Redirect::to(uri!("/"));
|
||||
return Redirect::to(uri!(week::week(week)));
|
||||
}
|
||||
let password_hash = password_hash_parse.unwrap();
|
||||
|
||||
|
@ -168,7 +168,7 @@ pub async fn login(form: Form<AuthForm>, mut db: Connection<Db>, cookies: &Cooki
|
|||
Err(error) => {
|
||||
error!("Login failed : coult not store auth token in database : {error}");
|
||||
cookies.add(("toast_error", "Impossible de se connecter !"));
|
||||
return Redirect::to(uri!("/"));
|
||||
return Redirect::to(uri!(week::week(week)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,11 +178,11 @@ pub async fn login(form: Form<AuthForm>, mut db: Connection<Db>, cookies: &Cooki
|
|||
Err(err) => {
|
||||
error!("Login failed : invalid password for {:?}\nError : {err}", new_user.name);
|
||||
cookies.add(("toast_error", "Impossible de se connecter !"));
|
||||
return Redirect::to(uri!("/"));
|
||||
return Redirect::to(uri!(week::week(week)));
|
||||
}
|
||||
}
|
||||
|
||||
Redirect::to(uri!("/"))
|
||||
Redirect::to(uri!(week::week(week)))
|
||||
}
|
||||
|
||||
pub fn bypass_auth_debug(cookies: &CookieJar<'_>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue