This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
2020-06-24 19:50:30 +00:00
|
|
|
"""passbook saml source signal listener"""
|
|
|
|
from django.contrib.auth.signals import user_logged_out
|
|
|
|
from django.dispatch import receiver
|
|
|
|
from django.http import HttpRequest
|
|
|
|
from structlog import get_logger
|
|
|
|
|
|
|
|
from passbook.core.models import User
|
|
|
|
|
|
|
|
LOGGER = get_logger()
|
|
|
|
|
|
|
|
|
|
|
|
@receiver(user_logged_out)
|
|
|
|
# pylint: disable=unused-argument
|
|
|
|
def on_user_logged_out(sender, request: HttpRequest, user: User, **_):
|
|
|
|
"""Delete temporary user if the `delete_on_logout` flag is enabled"""
|
2020-06-24 20:27:14 +00:00
|
|
|
if not user:
|
|
|
|
return
|
2020-06-24 19:50:30 +00:00
|
|
|
if "saml" in user.attributes:
|
|
|
|
if "delete_on_logout" in user.attributes["saml"]:
|
|
|
|
if user.attributes["saml"]["delete_on_logout"]:
|
|
|
|
LOGGER.debug("Deleted temporary user", user=user)
|
|
|
|
user.delete()
|