Toolbar with logout button

This commit is contained in:
Al Beano 2017-07-16 21:22:13 +01:00
parent 2afe5b1918
commit ec72bd2a1e
2 changed files with 45 additions and 0 deletions

View File

@ -57,11 +57,20 @@ hook 'before' => sub {
my $uid = cookieval("id"); my $uid = cookieval("id");
my $token = cookieval("token"); my $token = cookieval("token");
my $auth = 0; my $auth = 0;
my $email;
if ($uid && $token) { if ($uid && $token) {
$auth = get_auth($uid, $token); $auth = get_auth($uid, $token);
$email = database->quick_lookup(
"user",
{
"id" => $uid,
},
"email",
);
} }
var auth => $auth; var auth => $auth;
var email => $email;
}; };
get qr{^/(index)?$} => sub { get qr{^/(index)?$} => sub {
@ -183,4 +192,12 @@ post '/login' => sub {
}; };
}; };
post '/logout' => sub {
cookie 'id' => undef;
cookie 'token' => undef;
template 'redir' => {
"redir" => "index",
};
};
true; true;

View File

@ -26,6 +26,9 @@ p {
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
} }
.toolbar {
border: 1px solid white;
}
a.bracketButton { a.bracketButton {
text-decoration: none; text-decoration: none;
@ -33,6 +36,17 @@ a.bracketButton {
a.bracketButton:hover { a.bracketButton:hover {
text-decoration: underline; text-decoration: underline;
} }
button.textButton {
background: none !important;
color: inherit;
border: none;
padding: 0 !important;
font: inherit;
cursor: pointer;
}
button.textButton:hover {
text-decoration: underline;
}
form.login>table>tbody>tr>td>label { form.login>table>tbody>tr>td>label {
margin-right: 10px; margin-right: 10px;
@ -49,6 +63,20 @@ table.domains>tbody>tr>td:first-child>* {
</style> </style>
</head> </head>
<body> <body>
<% IF vars.auth %>
<div class="toolbar">
<div class="body">
<span>
Logged in as <% vars.email | html_entity %>
</span>
<span style="float:right;">
<form action="/logout" method="POST">
[&nbsp;<button class="textButton" action="submit">log&nbsp;out</button>&nbsp;]
</form>
</span>
</div>
</div>
<% END %>
<% content %> <% content %>
</body> </body>
</html> </html>