diff --git a/web/src/endpoints/user/get_login.rs b/web/src/endpoints/user/get_login.rs index 097fbd58..dbcce787 100644 --- a/web/src/endpoints/user/get_login.rs +++ b/web/src/endpoints/user/get_login.rs @@ -1,21 +1,34 @@ use actix_identity::Identity; -use actix_web::{http::header::LOCATION, HttpResponse, Responder}; +use actix_web::{http::header::LOCATION, web, HttpResponse, Responder}; use rinja::Template; +use serde::Deserialize; use crate::utils::ApplicationError; #[derive(Template)] #[template(path = "user/login.html")] -struct LoginTemplate {} +struct LoginTemplate { + next: Option, +} + +#[derive(Deserialize)] +struct LoginQuery { + next: Option, +} #[actix_web::get("/login")] -async fn get(user: Option) -> Result { +async fn get( + user: Option, + query: web::Query, +) -> Result { if user.is_some() { Ok(HttpResponse::Found() - .insert_header((LOCATION, "/")) + .insert_header((LOCATION, query.next.clone().unwrap_or("/".to_string()))) .finish()) } else { - let template = LoginTemplate {}; + let template = LoginTemplate { + next: query.next.clone(), + }; Ok(HttpResponse::Ok().body(template.render()?)) } diff --git a/web/src/endpoints/user/post_login.rs b/web/src/endpoints/user/post_login.rs index 6ff79a79..bdc656e8 100644 --- a/web/src/endpoints/user/post_login.rs +++ b/web/src/endpoints/user/post_login.rs @@ -9,6 +9,7 @@ use crate::{models::User, utils::auth::hash_plain_password_with_salt}; pub struct LoginForm { pub email: String, pub password: String, + pub next: Option, } #[actix_web::post("/login")] @@ -28,9 +29,11 @@ async fn post( .await .unwrap(); + let location = form.next.unwrap_or("/".to_string()); + return HttpResponse::Found() - .insert_header(("LOCATION", "/")) - .insert_header(("HX-LOCATION", "/")) + .insert_header(("LOCATION", location.clone())) + .insert_header(("HX-LOCATION", location)) .finish(); } } diff --git a/web/src/middleware/redirect_to_login.rs b/web/src/middleware/redirect_to_login.rs index 7723ebce..490613f5 100644 --- a/web/src/middleware/redirect_to_login.rs +++ b/web/src/middleware/redirect_to_login.rs @@ -56,9 +56,10 @@ where && !request.path().starts_with("/static") { let (request, _pl) = request.into_parts(); + let next_location = format!("/login?next={}", request.uri()); let response = HttpResponse::Found() - .insert_header((http::header::LOCATION, "/login")) + .insert_header((http::header::LOCATION, next_location)) .finish() // constructed responses map to "right" body .map_into_right_body(); diff --git a/web/src/utils/test_helper/test_requests.rs b/web/src/utils/test_helper/test_requests.rs index 12bcd14f..d54766a6 100644 --- a/web/src/utils/test_helper/test_requests.rs +++ b/web/src/utils/test_helper/test_requests.rs @@ -59,6 +59,7 @@ where let login_form = LoginForm { email: "abc".to_string(), password: "abc".to_string(), + next: None }; let login_req = test::TestRequest::post() diff --git a/web/templates/events/new_or_edit.html b/web/templates/events/new_or_edit.html index dff47b76..a556883a 100644 --- a/web/templates/events/new_or_edit.html +++ b/web/templates/events/new_or_edit.html @@ -74,7 +74,7 @@ {% let f = "%H:%M" %}
+ %}{{ event.start_time.format(f) }}{% else %}00:00{% endif %}" {{ disabled|cond_show("disabled") }} />
Brass - Anmeldung
+ + {% if let Some(next) = next %} + + {% endif %} +