From 6fe5f1681f47a64070020502a9e862926c799f29 Mon Sep 17 00:00:00 2001 From: Benbb96 Date: Tue, 7 May 2024 14:54:05 +0200 Subject: [PATCH 1/7] fix logout in Django 5 with POST action instead of GET --- helpdesk/templates/helpdesk/navigation-header.html | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/helpdesk/templates/helpdesk/navigation-header.html b/helpdesk/templates/helpdesk/navigation-header.html index d63dabe0..5ec166d6 100644 --- a/helpdesk/templates/helpdesk/navigation-header.html +++ b/helpdesk/templates/helpdesk/navigation-header.html @@ -58,7 +58,9 @@ {% trans "System Settings" %} {% endif %} - {% trans "Logout" %} +
{% csrf_token %} + +
{% else %} @@ -82,8 +84,10 @@ From 2d561d15c8ce8a52dfd64df21c9ec48c7429d9f0 Mon Sep 17 00:00:00 2001 From: Benbb96 Date: Tue, 7 May 2024 15:43:12 +0200 Subject: [PATCH 2/7] fix design on login/logout button when not staff --- .../templates/helpdesk/navigation-header.html | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/helpdesk/templates/helpdesk/navigation-header.html b/helpdesk/templates/helpdesk/navigation-header.html index 5ec166d6..417a6451 100644 --- a/helpdesk/templates/helpdesk/navigation-header.html +++ b/helpdesk/templates/helpdesk/navigation-header.html @@ -59,7 +59,9 @@ {% endif %}
{% csrf_token %} - +
@@ -82,13 +84,17 @@ {{user.username}} - {% endif %} From b1316214c7805ca71754f5d504e5ac40a8886cc0 Mon Sep 17 00:00:00 2001 From: Benbb96 Date: Tue, 7 May 2024 15:50:51 +0200 Subject: [PATCH 3/7] replace hardcoded path ../ to reverse_lazy URL --- helpdesk/templates/helpdesk/registration/login.html | 4 +++- helpdesk/urls.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/helpdesk/templates/helpdesk/registration/login.html b/helpdesk/templates/helpdesk/registration/login.html index a6ae234a..f76a493c 100644 --- a/helpdesk/templates/helpdesk/registration/login.html +++ b/helpdesk/templates/helpdesk/registration/login.html @@ -36,7 +36,9 @@ - + {% if next %} + + {% endif %} {% csrf_token %} diff --git a/helpdesk/urls.py b/helpdesk/urls.py index bbccd354..752d40fc 100644 --- a/helpdesk/urls.py +++ b/helpdesk/urls.py @@ -9,7 +9,7 @@ urls.py - Mapping of URL's to our various views. Note we always used NAMED from django.contrib.auth import views as auth_views from django.contrib.auth.decorators import login_required -from django.urls import include, path, re_path +from django.urls import include, path, re_path, reverse_lazy from django.views.generic import TemplateView from helpdesk import settings as helpdesk_settings from helpdesk.decorators import helpdesk_staff_member_required, protect_view @@ -215,7 +215,7 @@ urlpatterns += [ path( "logout/", auth_views.LogoutView.as_view( - template_name="helpdesk/registration/login.html", next_page="../" + template_name="helpdesk/registration/login.html", next_page=reverse_lazy("helpdesk:home") ), name="logout", ), From 485ac1294cb37a70b671b06ecd2370ca266dd275 Mon Sep 17 00:00:00 2001 From: Benbb96 Date: Wed, 8 May 2024 15:47:14 +0200 Subject: [PATCH 4/7] remove next_page parameter and show how to set LOGOUT_REDIRECT_URL in settings --- demo/demodesk/config/settings.py | 2 ++ helpdesk/urls.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/demo/demodesk/config/settings.py b/demo/demodesk/config/settings.py index a8366d22..6e99d4f0 100644 --- a/demo/demodesk/config/settings.py +++ b/demo/demodesk/config/settings.py @@ -124,6 +124,8 @@ HELPDESK_SHOW_CHANGE_PASSWORD = True HELPDESK_REDIRECT_TO_LOGIN_BY_DEFAULT = False LOGIN_URL = 'helpdesk:login' LOGIN_REDIRECT_URL = 'helpdesk:home' +# You can also redirect to a specific page after logging out (instead of logout page) +# LOGOUT_REDIRECT_URL = 'helpdesk:home' # Database # - by default, we use SQLite3 for the demo, but you can also diff --git a/helpdesk/urls.py b/helpdesk/urls.py index 752d40fc..224d7fa2 100644 --- a/helpdesk/urls.py +++ b/helpdesk/urls.py @@ -215,7 +215,7 @@ urlpatterns += [ path( "logout/", auth_views.LogoutView.as_view( - template_name="helpdesk/registration/login.html", next_page=reverse_lazy("helpdesk:home") + template_name="helpdesk/registration/logged_out.html" ), name="logout", ), From 7643e18acc07d7b7c93b8a4afa271838b6fe93e8 Mon Sep 17 00:00:00 2001 From: Benbb96 Date: Wed, 8 May 2024 16:01:26 +0200 Subject: [PATCH 5/7] Explain login/logout redirect settings in documentation --- docs/install.rst | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/install.rst b/docs/install.rst index a72de66a..f486defc 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -162,9 +162,16 @@ errors with trying to create User settings. following to ``settings.py`` to get your Django installation to use the login view included in ``django-helpdesk``:: - LOGIN_URL = '/helpdesk/login/' + LOGIN_URL = 'helpdesk:login' - Alter the URL to suit your installation path. + Alter the view name to suit your installation path. + + You can also add following settings to handle redirects after logging in or out:: + + LOGIN_REDIRECT_URL = 'helpdesk:home' + LOGOUT_REDIRECT_URL = 'helpdesk:home' + + If you don't set ``LOGOUT_REDIRECT_URL``, a logout confirmation page will be displayed. 8. Load initial e-mail templates, otherwise you will not be able to send e-mail:: From ef5a43a3e28041ee7ab79de65246f7deda951725 Mon Sep 17 00:00:00 2001 From: Benbb96 Date: Wed, 8 May 2024 16:05:22 +0200 Subject: [PATCH 6/7] remove unused import --- helpdesk/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpdesk/urls.py b/helpdesk/urls.py index 224d7fa2..02345389 100644 --- a/helpdesk/urls.py +++ b/helpdesk/urls.py @@ -9,7 +9,7 @@ urls.py - Mapping of URL's to our various views. Note we always used NAMED from django.contrib.auth import views as auth_views from django.contrib.auth.decorators import login_required -from django.urls import include, path, re_path, reverse_lazy +from django.urls import include, path, re_path from django.views.generic import TemplateView from helpdesk import settings as helpdesk_settings from helpdesk.decorators import helpdesk_staff_member_required, protect_view From 306a01a8b436205f6e48087ba1ff5e2e6e244ee0 Mon Sep 17 00:00:00 2001 From: Benbb96 Date: Wed, 8 May 2024 16:25:49 +0200 Subject: [PATCH 7/7] add login again button and reformat logged_out.html --- .../helpdesk/registration/logged_out.html | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/helpdesk/templates/helpdesk/registration/logged_out.html b/helpdesk/templates/helpdesk/registration/logged_out.html index e7146545..f2d5c2b1 100644 --- a/helpdesk/templates/helpdesk/registration/logged_out.html +++ b/helpdesk/templates/helpdesk/registration/logged_out.html @@ -1,13 +1,25 @@ {% extends "helpdesk/public_base.html" %}{% load i18n %} {% block helpdesk_title %}{% trans "Logged Out" %}{% endblock %} -{% block helpdesk_body %}{% blocktrans %} - -
-
-

Successfully Logged Out

-

Thanks for being here. Hopefully you've helped resolve a few tickets and made the world a better place.

+{% block helpdesk_body %} + {% blocktrans %} +
+
+

Successfully Logged Out

+

+ Thanks for being here. Hopefully you've helped resolve a few tickets + and made the world a better place. +

+
+ {% endblocktrans %} + +
+ + - -{% endblocktrans %}{% endblock %} +{% endblock %}