Mercurial > lbo > hg > analyrics
changeset 19:b9f49b4630be
Implement custom deploy path
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Mon, 11 Jul 2022 20:17:02 -0700 |
parents | ab4b3012fde3 |
children | c6f15ffef3d3 |
files | Rocket.toml src/main.rs |
diffstat | 2 files changed, 12 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/Rocket.toml Mon Jul 11 20:12:05 2022 -0700 +++ b/Rocket.toml Mon Jul 11 20:17:02 2022 -0700 @@ -16,3 +16,4 @@ secret_key = "edeaaff3f1774ad2888673770c6d64097e391bc362d7d6fb34982ddf0efd18cb" template_dir = "assets" asset_path = "assets/static" +deploy_path = "/"
--- a/src/main.rs Mon Jul 11 20:12:05 2022 -0700 +++ b/src/main.rs Mon Jul 11 20:17:02 2022 -0700 @@ -242,6 +242,7 @@ #[rocket::get("/login")] async fn route_login_form<'r>( + cc: &rocket::State<CustomConfig>, flash: Option<FlashMessage<'_>>, cookies: &CookieJar<'_>, ) -> Result<LoginResponse, InternalServerError> { @@ -253,7 +254,7 @@ } if let Some(cookie) = cookies.get_private(USER_ID_COOKIE_KEY) { Ok(LoginResponse::LoggedInAlready { - redirect: Redirect::to(rocket::uri!("/")), + redirect: Redirect::to(cc.deploy_path.clone()), }) } else { Ok(LoginResponse::Ok { @@ -263,12 +264,14 @@ } #[rocket::post("/logout")] -fn route_logout(cookies: &CookieJar<'_>) -> Flash<Redirect> { +fn route_logout( + cc: &rocket::State<CustomConfig>, + cookies: &CookieJar<'_>) -> Flash<Redirect> { if let Some(cookie) = cookies.get_private(USER_ID_COOKIE_KEY) { cookies.remove_private(cookie); } Flash::success( - Redirect::to(rocket::uri!("/")), + Redirect::to(cc.deploy_path.clone()), format!("Logged out. Goodbye!"), ) } @@ -282,6 +285,7 @@ #[rocket::post("/login", data = "<login>")] async fn route_login_post( mut db: Connection<ConfigDB>, + cc: &rocket::State<CustomConfig>, cookies: &CookieJar<'_>, login: Form<LoginForm>, ) -> Flash<Redirect> { @@ -294,14 +298,14 @@ Ok(true) => { let c = Cookie::new(USER_ID_COOKIE_KEY, login.username.clone()); cookies.add_private(c); - Flash::success(Redirect::to(rocket::uri!("/")), "Successfully logged in.") + Flash::success(Redirect::to(cc.deploy_path.clone()), "Successfully logged in.") } Ok(false) => Flash::error( - Redirect::to(rocket::uri!("/login")), + Redirect::to(format!("{}/login", cc.deploy_path)), "User/password not found", ), Err(e) => Flash::error( - Redirect::to(rocket::uri!("/login")), + Redirect::to(format!("{}/login", cc.deploy_path)), format!("User/password lookup failed: {}", e), ), } @@ -510,6 +514,7 @@ #[serde(crate = "rocket::serde")] struct CustomConfig { asset_path: String, + deploy_path: String, } #[rocket::launch]