django-allauth-cas/allauth_cas/signals.py

31 lines
901 B
Python
Raw Normal View History

2017-12-29 18:19:01 +01:00
from allauth.account.adapter import get_adapter
2017-07-25 18:31:42 +02:00
from allauth.account.utils import get_next_redirect_url
from allauth.socialaccount import providers
from django.contrib.auth.signals import user_logged_out
from django.dispatch import receiver
2017-07-25 18:31:42 +02:00
from . import CAS_PROVIDER_SESSION_KEY
@receiver(user_logged_out)
def cas_account_logout(sender, request, **kwargs):
provider_id = request.session.get(CAS_PROVIDER_SESSION_KEY)
2017-12-29 18:19:01 +01:00
if not provider_id:
2017-07-25 18:31:42 +02:00
return
provider = providers.registry.by_id(provider_id, request)
2017-12-29 18:19:01 +01:00
if not provider.message_suggest_caslogout_on_logout(request):
2017-07-25 18:31:42 +02:00
return
next_page = get_next_redirect_url(request) or get_adapter(
request
).get_logout_redirect_url(request)
2017-07-25 18:31:42 +02:00
2017-12-29 18:19:01 +01:00
provider.add_message_suggest_caslogout(
request,
next_page=next_page,
2017-12-29 18:19:01 +01:00
level=provider.message_suggest_caslogout_on_logout_level(request),
)