clearattempts.py 656 B

1234567891011121314
  1. from datetime import timedelta
  2. from django.core.exceptions import ValidationError, NON_FIELD_ERRORS
  3. from django.core.management.base import BaseCommand, CommandError
  4. from django.utils import timezone
  5. from misago.security.models import SignInAttempt
  6. class Command(BaseCommand):
  7. """
  8. This command is intended to work as CRON job fired every few days to remove failed sign-in attempts
  9. """
  10. help = 'Clears sign-in attempts log'
  11. def handle(self):
  12. SignInAttempt.objects.filter(date__lte=timezone.now() - timedelta(hours=24)).delete()
  13. self.stdout.write('Failed Sign-In attempts older than 24h have been removed.\n')