From 5cf820e44f5ff0766ba49b51eaf99c12121ffe84 Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Sun, 19 Jun 2016 13:00:09 +0200 Subject: [PATCH] Add a command to clean old federated users --- .../management/commands/cas_clean_federate.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 cas_server/management/commands/cas_clean_federate.py diff --git a/cas_server/management/commands/cas_clean_federate.py b/cas_server/management/commands/cas_clean_federate.py new file mode 100644 index 0000000..4c60ed5 --- /dev/null +++ b/cas_server/management/commands/cas_clean_federate.py @@ -0,0 +1,19 @@ +from django.core.management.base import BaseCommand +from django.utils.translation import ugettext_lazy as _ +from django.utils import timezone + +from datetime import timedelta + +from ... import models +from ...default_settings import settings + + +class Command(BaseCommand): + args = '' + help = _(u"Clean old federated users") + + def handle(self, *args, **options): + federated_users = models.FederatedUser.objects.filter(last_update__lt=(timezone.now() - timedelta(seconds=settings.CAS_TICKET_TIMEOUT))) + for user in federated_users: + if not models.User.objects.filter(username='%s@%s' % (user.username, user.provider)): + user.delete()