From 0d32179d07de6533bf03871d4d102f5ff5c0e60a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Sun, 1 Dec 2019 21:15:14 +0100 Subject: [PATCH] Logout button in admin page --- src/api/admin.rs | 9 +++++++++ src/static/templates/admin/base.hbs | 19 +++++++++++++++---- src/static/templates/admin/login.hbs | 2 +- src/static/templates/admin/page.hbs | 2 +- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/api/admin.rs b/src/api/admin.rs index b127c46..2b7c7df 100644 --- a/src/api/admin.rs +++ b/src/api/admin.rs @@ -26,6 +26,7 @@ pub fn routes() -> Vec { post_admin_login, admin_page, invite_user, + logout, delete_user, deauth_user, remove_2fa, @@ -109,6 +110,7 @@ struct AdminTemplateData { users: Vec, config: Value, can_backup: bool, + logged_in: bool } impl AdminTemplateData { @@ -119,6 +121,7 @@ impl AdminTemplateData { users, config: CONFIG.prepare_json(), can_backup: *CAN_BACKUP, + logged_in: true } } @@ -166,6 +169,12 @@ fn invite_user(data: Json, _token: AdminToken, conn: DbConn) -> Empt } } +#[get("/logout")] +fn logout(mut cookies: Cookies) -> Result { + cookies.remove(Cookie::named(COOKIE_NAME)); + Ok(Redirect::to(ADMIN_PATH)) +} + #[get("/users")] fn get_users(_token: AdminToken, conn: DbConn) -> JsonResult { let users = User::get_all(&conn); diff --git a/src/static/templates/admin/base.hbs b/src/static/templates/admin/base.hbs index 351abcb..f61ae6a 100644 --- a/src/static/templates/admin/base.hbs +++ b/src/static/templates/admin/base.hbs @@ -33,7 +33,7 @@ -