django-allauth-cas/allauth_cas/signals.py

33 lines
928 B
Python
Raw Normal View History

2017-07-25 18:31:42 +02:00
# -*- coding: utf-8 -*-
from django.contrib.auth.signals import user_logged_out
from django.dispatch import receiver
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 . 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
2017-12-29 18:19:01 +01:00
next_page = (
2017-07-25 18:31:42 +02:00
get_next_redirect_url(request) or
2017-12-29 18:19:01 +01:00
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,
level=provider.message_suggest_caslogout_on_logout_level(request),
)