frontend: Add button to log out

This commit is contained in:
Lennart
2025-04-13 15:49:27 +02:00
parent 0c5002f357
commit fe0bab00f6
3 changed files with 14 additions and 1 deletions

View File

@@ -54,6 +54,9 @@ li.collection-list-item {
}
</style>
<h1>Welcome {{ user_id }}!</h1>
<form method="POST" action="/frontend/logout">
<button type="submit">Log out</button>
</form>
<h2>Calendars</h2>
<ul>

View File

@@ -16,7 +16,7 @@ use oidc::{route_get_oidc, route_get_oidc_callback};
use routes::{
addressbook::{route_addressbook, route_addressbook_restore},
calendar::{route_calendar, route_calendar_restore},
login::{route_get_login, route_post_login},
login::{route_get_login, route_post_login, route_post_logout},
};
use rustical_store::{
Addressbook, AddressbookStore, Calendar, CalendarStore,
@@ -162,6 +162,11 @@ pub fn configure_frontend<AP: AuthenticationProvider, CS: CalendarStore, AS: Add
.route(web::method(Method::GET).to(route_get_login))
.route(web::method(Method::POST).to(route_post_login::<AP>)),
)
.service(
web::resource("/logout")
.name("frontend_logout")
.route(web::method(Method::POST).to(route_post_logout)),
)
.service(
web::resource("/login/oidc")
.name("frontend_login_oidc")

View File

@@ -54,3 +54,8 @@ pub async fn route_post_login<AP: AuthenticationProvider>(
ErrorUnauthorized("Unauthorized").error_response()
}
}
pub async fn route_post_logout(req: HttpRequest, session: Session) -> Redirect {
session.remove("user");
Redirect::to(req.url_for_static("frontend_login").unwrap().to_string()).see_other()
}