vw_small

Hardened fork of Vaultwarden (https://github.com/dani-garcia/vaultwarden) with fewer features.
git clone https://git.philomathiclife.com/repos/vw_small
Log | Files | Refs | README

commit 0d32179d07de6533bf03871d4d102f5ff5c0e60a
parent b45b02b37eea6bd556d696fc3d324d577a0e52dc
Author: Daniel GarcĂ­a <dani-garcia@users.noreply.github.com>
Date:   Sun,  1 Dec 2019 21:15:14 +0100

Logout button in admin page

Diffstat:
Msrc/api/admin.rs | 9+++++++++
Msrc/static/templates/admin/base.hbs | 19+++++++++++++++----
Msrc/static/templates/admin/login.hbs | 2+-
Msrc/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 @@ -26,6 +26,7 @@ pub fn routes() -> Vec<Route> { post_admin_login, admin_page, invite_user, + logout, delete_user, deauth_user, remove_2fa, @@ -109,6 +110,7 @@ struct AdminTemplateData { users: Vec<Value>, 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<InviteData>, _token: AdminToken, conn: DbConn) -> Empt } } +#[get("/logout")] +fn logout(mut cookies: Cookies) -> Result<Redirect, ()> { + 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 @@ -33,7 +33,7 @@ </head> <body class="bg-light"> - <nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top shadow"> + <nav class="navbar navbar-expand-sm navbar-dark bg-dark fixed-top shadow"> <a class="navbar-brand" href="#">Bitwarden_rs</a> <div class="navbar-collapse"> <ul class="navbar-nav"> @@ -45,9 +45,20 @@ </li> </ul> </div> - {{#if version}} - <div class="navbar-text">Version: {{version}}</div> - {{/if}} + + <ul class="navbar-nav"> + {{#if version}} + <li class="nav-item"> + <span class="navbar-text mr-2">Version: {{version}}</span> + </li> + {{/if}} + + {{#if logged_in}} + <li class="nav-item"> + <a class="nav-link" href="/admin/logout">Log Out</a> + </li> + {{/if}} + </ul> </nav> {{> (page_content) }} diff --git a/src/static/templates/admin/login.hbs b/src/static/templates/admin/login.hbs @@ -14,7 +14,7 @@ <form class="form-inline" method="post"> <input type="password" class="form-control w-50 mr-2" name="token" placeholder="Enter admin token"> - <button type="submit" class="btn btn-primary">Save</button> + <button type="submit" class="btn btn-primary">Enter</button> </form> </div> </div> diff --git a/src/static/templates/admin/page.hbs b/src/static/templates/admin/page.hbs @@ -191,7 +191,7 @@ <script> function reload() { window.location.reload(); } - function msg(text) { alert(text); reload(); } + function msg(text) { text && alert(text); reload(); } function identicon(email) { const data = new Identicon(md5(email), { size: 48, format: 'svg' }); return "data:image/svg+xml;base64," + data.toString();