Add our own logout view
This commit is contained in:
parent
092a92d986
commit
024eae0e1a
5 changed files with 34 additions and 9 deletions
|
@ -80,16 +80,19 @@
|
||||||
</li>
|
</li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li class="sidebar-item">
|
<li class="sidebar-item">
|
||||||
<a href="{% url 'profile' %}" class='sidebar-link'>
|
<a href="{% url 'frontend:profile' %}" class='sidebar-link'>
|
||||||
<i class="bi bi-file-person"></i>
|
<i class="bi bi-file-person"></i>
|
||||||
<span>{% translate 'Profile' %}</span>
|
<span>{% translate 'Profile' %}</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="sidebar-item">
|
<li class="sidebar-item">
|
||||||
<a href="{% url 'account_logout' %}" class='sidebar-link'>
|
<form action="{% url 'frontend:logout' %}" method="post">
|
||||||
<i class="bi bi-box-arrow-right"></i>
|
{% csrf_token %}
|
||||||
<span>{% translate 'Log out' %}</span>
|
<button type="submit" class='sidebar-link btn'>
|
||||||
</a>
|
<i class="bi bi-box-arrow-right"></i>
|
||||||
|
<span>{% translate 'Log out' %}</span>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
9
src/servala/frontend/urls.py
Normal file
9
src/servala/frontend/urls.py
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
from servala.frontend import views
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path("accounts/profile/", views.ProfileView.as_view(), name="profile"),
|
||||||
|
path("accounts/logout/", views.LogoutView.as_view(), name="logout"),
|
||||||
|
path("", views.IndexView.as_view(), name="index"),
|
||||||
|
]
|
|
@ -1,6 +1,8 @@
|
||||||
|
from .auth import LogoutView
|
||||||
from .generic import IndexView, ProfileView
|
from .generic import IndexView, ProfileView
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"IndexView",
|
"IndexView",
|
||||||
|
"LogoutView",
|
||||||
"ProfileView",
|
"ProfileView",
|
||||||
]
|
]
|
||||||
|
|
12
src/servala/frontend/views/auth.py
Normal file
12
src/servala/frontend/views/auth.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
from allauth.account.internal import flows
|
||||||
|
from allauth.account.utils import get_next_redirect_url
|
||||||
|
from django.shortcuts import redirect
|
||||||
|
from django.views import View
|
||||||
|
|
||||||
|
|
||||||
|
class LogoutView(View):
|
||||||
|
|
||||||
|
def post(self, request):
|
||||||
|
flows.logout.logout(request)
|
||||||
|
url = get_next_redirect_url(request, "next") or "/"
|
||||||
|
return redirect(url)
|
|
@ -6,7 +6,7 @@ from django.urls import path
|
||||||
from django.urls.conf import include
|
from django.urls.conf import include
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from servala.frontend import views
|
from servala.frontend import urls
|
||||||
|
|
||||||
admin.site.site_title = _("Servala Admin")
|
admin.site.site_title = _("Servala Admin")
|
||||||
admin.site.site_header = _("Servala Management")
|
admin.site.site_header = _("Servala Management")
|
||||||
|
@ -14,13 +14,12 @@ admin.site.index_title = _("Dashboard")
|
||||||
admin.site.login = secure_admin_login(admin.site.login)
|
admin.site.login = secure_admin_login(admin.site.login)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
path("admin/", admin.site.urls),
|
||||||
|
path("", include((urls, "servala.frontend"), namespace="frontend")),
|
||||||
# This adds the allauth urls to the project:
|
# This adds the allauth urls to the project:
|
||||||
# - accounts/keycloak/login/
|
# - accounts/keycloak/login/
|
||||||
# - accounts/keycloak/login/callback/
|
# - accounts/keycloak/login/callback/
|
||||||
path("accounts/", include("allauth.urls")),
|
path("accounts/", include("allauth.urls")),
|
||||||
path("accounts/profile/", views.ProfileView.as_view(), name="profile"),
|
|
||||||
path("admin/", admin.site.urls),
|
|
||||||
path("", views.IndexView.as_view(), name="index"),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# Serve static and media files in development
|
# Serve static and media files in development
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue