mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
parent
968ce53689
commit
22d932fafc
5 changed files with 83 additions and 0 deletions
|
|
@ -33,6 +33,7 @@ from .views.special import (
|
|||
JsonDataView,
|
||||
PatternPortfolioView,
|
||||
AuthTokenView,
|
||||
LogoutView,
|
||||
PermissionsDebugView,
|
||||
MessagesDebugView,
|
||||
)
|
||||
|
|
@ -853,6 +854,9 @@ class Datasette:
|
|||
add_route(
|
||||
AuthTokenView.as_view(self), r"/-/auth-token$",
|
||||
)
|
||||
add_route(
|
||||
LogoutView.as_view(self), r"/-/logout$",
|
||||
)
|
||||
add_route(
|
||||
PermissionsDebugView.as_view(self), r"/-/permissions$",
|
||||
)
|
||||
|
|
|
|||
25
datasette/templates/logout.html
Normal file
25
datasette/templates/logout.html
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Log out{% endblock %}
|
||||
|
||||
{% block nav %}
|
||||
<p class="crumbs">
|
||||
<a href="{{ base_url }}">home</a>
|
||||
</p>
|
||||
{{ super() }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h1>Log out</h1>
|
||||
|
||||
<p>You are logged in as <strong>{{ actor.id or actor }}</strong></p>
|
||||
|
||||
<form action="/-/logout" method="post">
|
||||
<div>
|
||||
<input type="hidden" name="csrftoken" value="{{ csrftoken() }}">
|
||||
<input type="submit" value="Log out">
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
|
|
@ -72,6 +72,23 @@ class AuthTokenView(BaseView):
|
|||
return Response("Invalid token", status=403)
|
||||
|
||||
|
||||
class LogoutView(BaseView):
|
||||
name = "logout"
|
||||
|
||||
def __init__(self, datasette):
|
||||
self.ds = datasette
|
||||
|
||||
async def get(self, request):
|
||||
if not request.actor:
|
||||
return Response.redirect("/")
|
||||
return await self.render(["logout.html"], request, {"actor": request.actor},)
|
||||
|
||||
async def post(self, request):
|
||||
response = Response.redirect("/")
|
||||
response.set_cookie("ds_actor", "", expires=0, max_age=0)
|
||||
return response
|
||||
|
||||
|
||||
class PermissionsDebugView(BaseView):
|
||||
name = "permissions_debug"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue