From 1a1005f80dc86b5289ff985e098f41804adb28a4 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 3 Mar 2019 20:13:54 +0100 Subject: [PATCH] remove audit's LoginAttempt --- passbook/audit/models.py | 40 --------------------------------------- passbook/audit/signals.py | 10 ++-------- 2 files changed, 2 insertions(+), 48 deletions(-) diff --git a/passbook/audit/models.py b/passbook/audit/models.py index f43cd5564..29338ee7a 100644 --- a/passbook/audit/models.py +++ b/passbook/audit/models.py @@ -75,43 +75,3 @@ class AuditEntry(UUIDModel): verbose_name = _('Audit Entry') verbose_name_plural = _('Audit Entries') - - -class LoginAttempt(CreatedUpdatedModel): - """Track failed login-attempts""" - - target_uid = models.CharField(max_length=254) - request_ip = models.GenericIPAddressField() - attempts = models.IntegerField(default=1) - - @staticmethod - def attempt(target_uid, request): - """Helper function to create attempt or count up existing one""" - if not target_uid: - return - client_ip, _ = get_client_ip(request) - # Since we can only use 254 chars for target_uid, truncate target_uid. - target_uid = target_uid[:254] - time_threshold = timezone.now() - timedelta(minutes=10) - existing_attempts = LoginAttempt.objects.filter( - target_uid=target_uid, - request_ip=client_ip, - last_updated__gt=time_threshold).order_by('created') - if existing_attempts.exists(): - attempt = existing_attempts.first() - attempt.attempts += 1 - attempt.save() - LOGGER.debug("Increased attempts on %s", attempt) - else: - attempt = LoginAttempt.objects.create( - target_uid=target_uid, - request_ip=client_ip) - LOGGER.debug("Created new attempt %s", attempt) - - def __str__(self): - return "LoginAttempt to %s from %s (x%d)" % (self.target_uid, - self.request_ip, self.attempts) - - class Meta: - - unique_together = (('target_uid', 'request_ip', 'created'),) diff --git a/passbook/audit/signals.py b/passbook/audit/signals.py index d26374326..a59fb35bd 100644 --- a/passbook/audit/signals.py +++ b/passbook/audit/signals.py @@ -1,9 +1,8 @@ """passbook audit signal listener""" -from django.contrib.auth.signals import (user_logged_in, user_logged_out, - user_login_failed) +from django.contrib.auth.signals import user_logged_in, user_logged_out from django.dispatch import receiver -from passbook.audit.models import AuditEntry, LoginAttempt +from passbook.audit.models import AuditEntry from passbook.core.signals import (invitation_created, invitation_used, user_signed_up) @@ -34,8 +33,3 @@ def on_invitation_used(sender, request, invitation, **kwargs): """Log Invitation usage""" AuditEntry.create(AuditEntry.ACTION_INVITE_USED, request, invitation_uuid=invitation.uuid.hex) - -@receiver(user_login_failed) -def on_user_login_failed(sender, request, credentials, **kwargs): - """Log failed login attempt""" - LoginAttempt.attempt(target_uid=credentials.get('username'), request=request)