store loation in kiosk cookie, to avoid having to handle each location separately

This commit is contained in:
philipp 2023-08-05 13:09:58 +02:00
parent 351ba1ba4e
commit e459a4e2d9

View File

@ -78,22 +78,21 @@ async fn show_kiosk(db: &State<SqlitePool>, _kios: KioskCookie) -> Template {
Template::render("log.completed", context!(logs)) Template::render("log.completed", context!(logs))
} }
#[get("/kiosk/ekrv2019")] #[get("/kiosk/ekrv2019/<loc>")]
fn new_kiosk(cookies: &CookieJar<'_>) -> Redirect { fn new_kiosk(cookies: &CookieJar<'_>, loc: String) -> Redirect {
let mut cookie = Cookie::new("kiosk", "yes".to_string()); let mut cookie = Cookie::new("kiosk", loc);
cookie.set_expires(OffsetDateTime::now_utc() + Duration::weeks(12)); cookie.set_expires(OffsetDateTime::now_utc() + Duration::weeks(12));
cookies.add_private(cookie); cookies.add_private(cookie);
Redirect::to("/log/Linz") Redirect::to("/log")
} }
#[get("/<loc>")] #[get("/")]
async fn kiosk( async fn kiosk(
db: &State<SqlitePool>, db: &State<SqlitePool>,
flash: Option<FlashMessage<'_>>, flash: Option<FlashMessage<'_>>,
_kiosk: KioskCookie, kiosk: KioskCookie,
loc: String,
) -> Template { ) -> 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 coxes = User::cox(db).await;
let users = User::all(db).await; let users = User::all(db).await;
let logtypes = LogType::all(db).await; let logtypes = LogType::all(db).await;
@ -246,7 +245,7 @@ mod test {
let response = req.dispatch().await; let response = req.dispatch().await;
assert_eq!(response.status(), Status::SeeOther); 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 req = client.get("/log");
let response = req.dispatch().await; let response = req.dispatch().await;