From 605447e00880cc5ee0dc229ed1f4c5bd3b17ba3e Mon Sep 17 00:00:00 2001 From: Rafael Leira Date: Fri, 22 Oct 2021 11:10:35 +0200 Subject: [PATCH] @paradxum requested changes -- signals.py --- simple_sso/{sso_client/models.py => signals.py} | 14 ++++++++++++-- simple_sso/sso_client/apps.py | 2 +- simple_sso/sso_server/apps.py | 2 +- simple_sso/sso_server/models.py | 10 ---------- 4 files changed, 14 insertions(+), 14 deletions(-) rename simple_sso/{sso_client/models.py => signals.py} (71%) diff --git a/simple_sso/sso_client/models.py b/simple_sso/signals.py similarity index 71% rename from simple_sso/sso_client/models.py rename to simple_sso/signals.py index 0e2bc4c..aaa37fd 100644 --- a/simple_sso/sso_client/models.py +++ b/simple_sso/signals.py @@ -1,10 +1,20 @@ -from simple_sso.settings import settings from django.urls import NoReverseMatch, reverse - +from simple_sso.settings import settings +from simple_sso.sso_server.models import Token from webservices.sync import SyncConsumer +def logout_token(sender, request, **kwargs): + """ + A signal receiver which removes a token when its users logs out. + """ + tokens = Token.objects.select_related('session').filter(session__session_key=request.session.session_key) + + for token in tokens: + token.delete() + + def logout_sso_client(sender, request, user, **kwargs): """ A signal receiver which notifies the server when the client have logged out. diff --git a/simple_sso/sso_client/apps.py b/simple_sso/sso_client/apps.py index 685a44d..db806e4 100644 --- a/simple_sso/sso_client/apps.py +++ b/simple_sso/sso_client/apps.py @@ -6,6 +6,6 @@ class SimpleSSOClient(AppConfig): name = 'simple_sso.sso_client' def ready(self): - from .models import logout_sso_client + from simple_sso.signals import logout_sso_client user_logged_out.connect( logout_sso_client, dispatch_uid='logout_sso_client') diff --git a/simple_sso/sso_server/apps.py b/simple_sso/sso_server/apps.py index 1eb7f02..7ff8e84 100644 --- a/simple_sso/sso_server/apps.py +++ b/simple_sso/sso_server/apps.py @@ -6,5 +6,5 @@ class SimpleSSOServer(AppConfig): name = 'simple_sso.sso_server' def ready(self): - from .models import logout_token + from simple_sso.signals import logout_token user_logged_out.connect(logout_token, dispatch_uid='logout_token') diff --git a/simple_sso/sso_server/models.py b/simple_sso/sso_server/models.py index 1f63d67..697895e 100644 --- a/simple_sso/sso_server/models.py +++ b/simple_sso/sso_server/models.py @@ -53,16 +53,6 @@ def rotate_keys(self): self.save() -def logout_token(sender, request, **kwargs): - """ - A signal receiver which removes a token when its users logs out. - """ - tokens = Token.objects.select_related('session').filter(session__session_key=request.session.session_key) - - for token in tokens: - token.delete() - - class Token(models.Model): consumer = models.ForeignKey( Consumer,