Logout button in admin page

This commit is contained in:
Daniel García 2019-12-01 21:15:14 +01:00
parent b45b02b37e
commit 0d32179d07
No known key found for this signature in database
GPG Key ID: FC8A7D14C3CD543A
4 changed files with 26 additions and 6 deletions

View File

@ -26,6 +26,7 @@ pub fn routes() -> Vec<Route> {
post_admin_login, post_admin_login,
admin_page, admin_page,
invite_user, invite_user,
logout,
delete_user, delete_user,
deauth_user, deauth_user,
remove_2fa, remove_2fa,
@ -109,6 +110,7 @@ struct AdminTemplateData {
users: Vec<Value>, users: Vec<Value>,
config: Value, config: Value,
can_backup: bool, can_backup: bool,
logged_in: bool
} }
impl AdminTemplateData { impl AdminTemplateData {
@ -119,6 +121,7 @@ impl AdminTemplateData {
users, users,
config: CONFIG.prepare_json(), config: CONFIG.prepare_json(),
can_backup: *CAN_BACKUP, 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")] #[get("/users")]
fn get_users(_token: AdminToken, conn: DbConn) -> JsonResult { fn get_users(_token: AdminToken, conn: DbConn) -> JsonResult {
let users = User::get_all(&conn); let users = User::get_all(&conn);

View File

@ -33,7 +33,7 @@
</head> </head>
<body class="bg-light"> <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> <a class="navbar-brand" href="#">Bitwarden_rs</a>
<div class="navbar-collapse"> <div class="navbar-collapse">
<ul class="navbar-nav"> <ul class="navbar-nav">
@ -45,9 +45,20 @@
</li> </li>
</ul> </ul>
</div> </div>
<ul class="navbar-nav">
{{#if version}} {{#if version}}
<div class="navbar-text">Version: {{version}}</div> <li class="nav-item">
<span class="navbar-text mr-2">Version: {{version}}</span>
</li>
{{/if}} {{/if}}
{{#if logged_in}}
<li class="nav-item">
<a class="nav-link" href="/admin/logout">Log Out</a>
</li>
{{/if}}
</ul>
</nav> </nav>
{{> (page_content) }} {{> (page_content) }}

View File

@ -14,7 +14,7 @@
<form class="form-inline" method="post"> <form class="form-inline" method="post">
<input type="password" class="form-control w-50 mr-2" name="token" placeholder="Enter admin token"> <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> </form>
</div> </div>
</div> </div>

View File

@ -191,7 +191,7 @@
<script> <script>
function reload() { window.location.reload(); } function reload() { window.location.reload(); }
function msg(text) { alert(text); reload(); } function msg(text) { text && alert(text); reload(); }
function identicon(email) { function identicon(email) {
const data = new Identicon(md5(email), { size: 48, format: 'svg' }); const data = new Identicon(md5(email), { size: 48, format: 'svg' });
return "data:image/svg+xml;base64," + data.toString(); return "data:image/svg+xml;base64," + data.toString();