2016-06-19 11:00:09 +00:00
|
|
|
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):
|
2016-06-20 12:20:49 +00:00
|
|
|
federated_users = models.FederatedUser.objects.filter(
|
|
|
|
last_update__lt=(timezone.now() - timedelta(seconds=settings.CAS_TICKET_TIMEOUT))
|
|
|
|
)
|
2016-06-23 15:18:53 +00:00
|
|
|
known_users = {user.username for user in models.User.objects.all()}
|
2016-06-19 11:00:09 +00:00
|
|
|
for user in federated_users:
|
2016-06-23 15:18:53 +00:00
|
|
|
if not ('%s@%s' % (user.username, user.provider)) in known_users:
|
2016-06-19 11:00:09 +00:00
|
|
|
user.delete()
|
2016-06-23 15:18:53 +00:00
|
|
|
models.FederateSLO.clean_deleted_sessions()
|