Commit 2c60a2f6 authored by Sybren A. Stüvel's avatar Sybren A. Stüvel

Redirect user back to the current site after logout

Without this, the user will remain at the login screen of Blender ID
after logging out. This is still the default behaviour when
`LOGOUT_REDIRECT_URL` is not set (or a falsy value).
parent 66fae322
Pipeline #31993169 failed with stages
in 2 minutes and 19 seconds
......@@ -28,7 +28,10 @@ Quick start
LOGIN_URL = '/oauth/login'
LOGOUT_URL = '/oauth/logout'
LOGIN_REDIRECT_URL = '/'
LOGIN_REDIRECT_URL = '/redir-target-after-login'
# Set to empty string to remain on Blender ID after logging out:
LOGOUT_REDIRECT_URL = '/redir-target-after-logout'
- Include the URLconf in your project urls.py like this::
......
......@@ -9,6 +9,7 @@ from django.conf import settings
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from django.db import transaction
from django.http import HttpRequest
from django.shortcuts import redirect
from django.urls import reverse
from django.utils.timezone import utc
......@@ -107,11 +108,20 @@ def callback_view(request):
return redirect(settings.LOGIN_REDIRECT_URL)
def logout_view(request):
"""Logout from My Data, and then from Blender ID.
def logout_view(request: HttpRequest):
"""Logout from this site, and then from Blender ID.
This helps perceiving My Data as part of Blender ID.
This helps perceiving the current site as part of Blender ID.
"""
from urllib.parse import quote
blender_id_oauth = blender_id_oauth_settings()
django.contrib.auth.logout(request)
return redirect(blender_id_oauth.url_logout)
redirect_url = blender_id_oauth.url_logout
if settings.LOGOUT_REDIRECT_URL:
next_url = request.build_absolute_uri(settings.LOGOUT_REDIRECT_URL)
quoted_next_url = quote(next_url)
redirect_url = f'{redirect_url}?next={quoted_next_url}'
return redirect(redirect_url)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment