add logout button
This commit is contained in:
parent
60c65c7044
commit
976ffe4551
16
buckler.py
16
buckler.py
|
@ -347,6 +347,22 @@ async def set_session(request):
|
||||||
return web.json_response(error)
|
return web.json_response(error)
|
||||||
|
|
||||||
|
|
||||||
|
@routes.get('/logout', name='logout')
|
||||||
|
@auth.auth_required
|
||||||
|
async def logout(request):
|
||||||
|
"""Deletes the users session cookie."""
|
||||||
|
async with request.app['pool'].acquire() as conn:
|
||||||
|
await conn.execute(
|
||||||
|
"DELETE FROM user_session "
|
||||||
|
"WHERE id = $1 AND user_id = $2",
|
||||||
|
request.cookies.get('session'), request['session']['id'])
|
||||||
|
login_url = request.app.router['login'].url_for()
|
||||||
|
resp = web.HTTPFound(location=login_url)
|
||||||
|
resp.set_cookie('userid', '', domain=config.server_domain, max_age=0)
|
||||||
|
resp.set_cookie('session', '', domain=config.server_domain, max_age=0)
|
||||||
|
raise resp
|
||||||
|
|
||||||
|
|
||||||
async def init_app():
|
async def init_app():
|
||||||
"""Initializes the application."""
|
"""Initializes the application."""
|
||||||
app = web.Application()
|
app = web.Application()
|
||||||
|
|
|
@ -17,6 +17,11 @@ header {
|
||||||
margin-right: 1em;
|
margin-right: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#username {
|
||||||
|
margin-left: auto;
|
||||||
|
margin-top: auto;
|
||||||
|
}
|
||||||
|
|
||||||
main {
|
main {
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 2em;
|
gap: 2em;
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
<header>
|
<header>
|
||||||
<object id="logo" title="Buckler logo" data="/static/buckler_icon.svg"></object>
|
<object id="logo" title="Buckler logo" data="/static/buckler_icon.svg"></object>
|
||||||
<h1>Buckler</h1>
|
<h1>Buckler</h1>
|
||||||
|
<span id="username">Logged in as: <b>{{ request['session']['username'] }}</b> (<a href="./logout">Logout</a>)</span>
|
||||||
</header>
|
</header>
|
||||||
<main>
|
<main>
|
||||||
<section>
|
<section>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user