mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 22:52:22 +00:00
frontend: Add button to log out
This commit is contained in:
@@ -54,6 +54,9 @@ li.collection-list-item {
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<h1>Welcome {{ user_id }}!</h1>
|
<h1>Welcome {{ user_id }}!</h1>
|
||||||
|
<form method="POST" action="/frontend/logout">
|
||||||
|
<button type="submit">Log out</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
<h2>Calendars</h2>
|
<h2>Calendars</h2>
|
||||||
<ul>
|
<ul>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ use oidc::{route_get_oidc, route_get_oidc_callback};
|
|||||||
use routes::{
|
use routes::{
|
||||||
addressbook::{route_addressbook, route_addressbook_restore},
|
addressbook::{route_addressbook, route_addressbook_restore},
|
||||||
calendar::{route_calendar, route_calendar_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::{
|
use rustical_store::{
|
||||||
Addressbook, AddressbookStore, Calendar, CalendarStore,
|
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::GET).to(route_get_login))
|
||||||
.route(web::method(Method::POST).to(route_post_login::<AP>)),
|
.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(
|
.service(
|
||||||
web::resource("/login/oidc")
|
web::resource("/login/oidc")
|
||||||
.name("frontend_login_oidc")
|
.name("frontend_login_oidc")
|
||||||
|
|||||||
@@ -54,3 +54,8 @@ pub async fn route_post_login<AP: AuthenticationProvider>(
|
|||||||
ErrorUnauthorized("Unauthorized").error_response()
|
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()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user