added /delete_session
This commit is contained in:
parent
b24061fb05
commit
b174c1d2e8
20
buckler.py
20
buckler.py
|
@ -336,6 +336,26 @@ async def delete_key(request):
|
||||||
raise web.HTTPFound(location=index_url)
|
raise web.HTTPFound(location=index_url)
|
||||||
|
|
||||||
|
|
||||||
|
@routes.post(config.url_prefix + '/delete_session', name='delete_session')
|
||||||
|
@auth.auth_required
|
||||||
|
async def delete_session(request):
|
||||||
|
"""Allows a user to delete a session ."""
|
||||||
|
data = await request.post()
|
||||||
|
async with request.app['pool'].acquire() as conn:
|
||||||
|
for key, value in data.items():
|
||||||
|
session_id = key.replace('session-', '', 1)
|
||||||
|
if not session_id:
|
||||||
|
continue
|
||||||
|
if value != 'on':
|
||||||
|
continue
|
||||||
|
await conn.execute(
|
||||||
|
"DELETE FROM user_session "
|
||||||
|
"WHERE id = $1 AND user_id = $2",
|
||||||
|
session_id, request['session']['id'])
|
||||||
|
index_url = request.app.router['index'].url_for()
|
||||||
|
raise web.HTTPFound(location=index_url)
|
||||||
|
|
||||||
|
|
||||||
async def init_app():
|
async def init_app():
|
||||||
"""Initializes the application."""
|
"""Initializes the application."""
|
||||||
app = web.Application()
|
app = web.Application()
|
||||||
|
|
|
@ -107,22 +107,27 @@
|
||||||
<h2>Active Sessions</h2>
|
<h2>Active Sessions</h2>
|
||||||
<article style="display: none;">
|
<article style="display: none;">
|
||||||
<hr>
|
<hr>
|
||||||
<table id="active_sessions">
|
<form action="{{ request.app.router['delete_session'].url_for() }}" method="POST" enctype="application/x-www-form-urlencoded">
|
||||||
<thead>
|
<table id="active_sessions">
|
||||||
<tr>
|
<thead>
|
||||||
<th>IP Address</th>
|
<tr>
|
||||||
<th>Delete</th>
|
<th>Session ID</th>
|
||||||
</tr>
|
<th>IP Address</th>
|
||||||
</thead>
|
<th>Delete</th>
|
||||||
<tbody>
|
</tr>
|
||||||
{% for session in active_sessions %}
|
</thead>
|
||||||
<tr>
|
<tbody>
|
||||||
<td>{{ session['ip_address'] }}</td>
|
{% for session in active_sessions %}
|
||||||
<td><input aria-label="Delete {{ session['id'][:5] }}" id="session-{{ session['id'][:5] }}" name="session-{{ session['id'][:5] }}" type="checkbox"></td>
|
<tr>
|
||||||
</tr>
|
<td><code>{{ session['id'][:5] }}...{{ session['id'][-5:] }}</code></td>
|
||||||
{% endfor %}
|
<td>{{ session['ip_address'] }}</td>
|
||||||
</tbody>
|
<td><input aria-label="Delete {{ session['id'][:5] }}...{{ session['id'][-5:] }}" id="session-{{ session['id'] }}" name="session-{{ session['id'] }}" type="checkbox"></td>
|
||||||
</table>
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<input type="submit" value="Delete">
|
||||||
|
</form>
|
||||||
</article>
|
</article>
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user