From e459a4e2d91bacd8773a89c983a19aef8c597c8b Mon Sep 17 00:00:00 2001 From: philipp Date: Sat, 5 Aug 2023 13:09:58 +0200 Subject: [PATCH] store loation in kiosk cookie, to avoid having to handle each location separately --- src/tera/log.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/tera/log.rs b/src/tera/log.rs index dbdd518..91433bc 100644 --- a/src/tera/log.rs +++ b/src/tera/log.rs @@ -78,22 +78,21 @@ async fn show_kiosk(db: &State, _kios: KioskCookie) -> Template { Template::render("log.completed", context!(logs)) } -#[get("/kiosk/ekrv2019")] -fn new_kiosk(cookies: &CookieJar<'_>) -> Redirect { - let mut cookie = Cookie::new("kiosk", "yes".to_string()); +#[get("/kiosk/ekrv2019/")] +fn new_kiosk(cookies: &CookieJar<'_>, loc: String) -> Redirect { + let mut cookie = Cookie::new("kiosk", loc); cookie.set_expires(OffsetDateTime::now_utc() + Duration::weeks(12)); cookies.add_private(cookie); - Redirect::to("/log/Linz") + Redirect::to("/log") } -#[get("/")] +#[get("/")] async fn kiosk( db: &State, flash: Option>, - _kiosk: KioskCookie, - loc: String, + kiosk: KioskCookie, ) -> Template { - let boats = Boat::all_at_location(db, loc).await; + let boats = Boat::all_at_location(db, kiosk.0).await; let coxes = User::cox(db).await; let users = User::all(db).await; let logtypes = LogType::all(db).await; @@ -246,7 +245,7 @@ mod test { let response = req.dispatch().await; assert_eq!(response.status(), Status::SeeOther); - assert_eq!(response.headers().get("Location").next(), Some("/log/Linz")); + assert_eq!(response.headers().get("Location").next(), Some("/log")); let req = client.get("/log"); let response = req.dispatch().await;