From 024eae0e1a899746fa92d11653e4d6a7acb14802 Mon Sep 17 00:00:00 2001 From: Tobias Kunze Date: Mon, 17 Mar 2025 09:12:58 +0100 Subject: [PATCH] Add our own logout view --- .../frontend/templates/includes/sidebar.html | 13 ++++++++----- src/servala/frontend/urls.py | 9 +++++++++ src/servala/frontend/views/__init__.py | 2 ++ src/servala/frontend/views/auth.py | 12 ++++++++++++ src/servala/urls.py | 7 +++---- 5 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 src/servala/frontend/urls.py create mode 100644 src/servala/frontend/views/auth.py diff --git a/src/servala/frontend/templates/includes/sidebar.html b/src/servala/frontend/templates/includes/sidebar.html index 287977a..2baecb5 100644 --- a/src/servala/frontend/templates/includes/sidebar.html +++ b/src/servala/frontend/templates/includes/sidebar.html @@ -80,16 +80,19 @@ {% else %} {% endif %} diff --git a/src/servala/frontend/urls.py b/src/servala/frontend/urls.py new file mode 100644 index 0000000..b9a0c6b --- /dev/null +++ b/src/servala/frontend/urls.py @@ -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"), +] diff --git a/src/servala/frontend/views/__init__.py b/src/servala/frontend/views/__init__.py index e712464..3fc930c 100644 --- a/src/servala/frontend/views/__init__.py +++ b/src/servala/frontend/views/__init__.py @@ -1,6 +1,8 @@ +from .auth import LogoutView from .generic import IndexView, ProfileView __all__ = [ "IndexView", + "LogoutView", "ProfileView", ] diff --git a/src/servala/frontend/views/auth.py b/src/servala/frontend/views/auth.py new file mode 100644 index 0000000..6b351f1 --- /dev/null +++ b/src/servala/frontend/views/auth.py @@ -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) diff --git a/src/servala/urls.py b/src/servala/urls.py index 8ddedb6..d1d40ec 100644 --- a/src/servala/urls.py +++ b/src/servala/urls.py @@ -6,7 +6,7 @@ from django.urls import path from django.urls.conf import include 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_header = _("Servala Management") @@ -14,13 +14,12 @@ admin.site.index_title = _("Dashboard") admin.site.login = secure_admin_login(admin.site.login) urlpatterns = [ + path("admin/", admin.site.urls), + path("", include((urls, "servala.frontend"), namespace="frontend")), # This adds the allauth urls to the project: # - accounts/keycloak/login/ # - accounts/keycloak/login/callback/ 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