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,
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);

View File

@ -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) }}

View File

@ -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>

View File

@ -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();