|
26 | 26 | HttpResponseRedirect,
|
27 | 27 | HttpResponseServerError,
|
28 | 28 | )
|
29 |
| -from django.shortcuts import render |
| 29 | +from django.shortcuts import render, resolve_url |
30 | 30 | from django.template import TemplateDoesNotExist
|
31 | 31 | from django.urls import reverse
|
32 | 32 | from django.utils.decorators import method_decorator
|
33 | 33 | from django.utils.module_loading import import_string
|
| 34 | +from django.utils.translation import gettext_lazy as _ |
34 | 35 | from django.views.decorators.csrf import csrf_exempt
|
35 | 36 | from django.views.generic import View
|
36 | 37 |
|
37 | 38 | from django.contrib import auth
|
38 | 39 | from django.contrib.auth.mixins import LoginRequiredMixin
|
39 |
| -from django.contrib.auth.views import LogoutView as AuthLogoutView |
| 40 | +from django.contrib.sites.shortcuts import get_current_site |
40 | 41 |
|
41 | 42 | import saml2
|
42 | 43 | from saml2.client_base import LogoutError
|
@@ -787,14 +788,29 @@ def do_logout_service(self, request, data, binding):
|
787 | 788 | return HttpResponseBadRequest("No SAMLResponse or SAMLRequest parameter found")
|
788 | 789 |
|
789 | 790 |
|
790 |
| -def finish_logout(request, response, next_page=None): |
| 791 | +def finish_logout(request, response): |
791 | 792 | if getattr(settings, "SAML_IGNORE_LOGOUT_ERRORS", False) or (
|
792 | 793 | response and response.status_ok()
|
793 | 794 | ):
|
794 |
| - if not next_page: |
795 |
| - next_page = getattr(settings, "LOGOUT_REDIRECT_URL", "/") |
796 |
| - logger.debug("Performing django logout with a next_page of %s", next_page) |
797 |
| - return AuthLogoutView.as_view()(request, next_page=next_page) |
| 795 | + logger.debug("Performing django logout.") |
| 796 | + |
| 797 | + auth.logout(request) |
| 798 | + |
| 799 | + if settings.LOGOUT_REDIRECT_URL is not None: |
| 800 | + return HttpResponseRedirect(resolve_url(settings.LOGOUT_REDIRECT_URL)) |
| 801 | + else: |
| 802 | + current_site = get_current_site(request) |
| 803 | + return render( |
| 804 | + request, |
| 805 | + "registration/logged_out.html", |
| 806 | + { |
| 807 | + "site": current_site, |
| 808 | + "site_name": current_site.name, |
| 809 | + "title": _("Logged out"), |
| 810 | + "subtitle": None, |
| 811 | + }, |
| 812 | + ) |
| 813 | + |
798 | 814 | logger.error("Unknown error during the logout")
|
799 | 815 | return render(request, "djangosaml2/logout_error.html", {})
|
800 | 816 |
|
|
0 commit comments