audit: fix usage of timezone-naive date-time
This commit is contained in:
parent
9abcc8852d
commit
85468f386e
|
@ -1,4 +1,5 @@
|
||||||
"""passbook audit models"""
|
"""passbook audit models"""
|
||||||
|
from datetime import timedelta
|
||||||
from json import dumps, loads
|
from json import dumps, loads
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
|
@ -6,6 +7,7 @@ from django.conf import settings
|
||||||
from django.contrib.auth.models import AnonymousUser
|
from django.contrib.auth.models import AnonymousUser
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.utils import timezone
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
from ipware import get_client_ip
|
from ipware import get_client_ip
|
||||||
from reversion import register
|
from reversion import register
|
||||||
|
@ -95,10 +97,11 @@ class LoginAttempt(CreatedUpdatedModel):
|
||||||
client_ip, _ = get_client_ip(request)
|
client_ip, _ = get_client_ip(request)
|
||||||
# Since we can only use 254 chars for target_uid, truncate target_uid.
|
# Since we can only use 254 chars for target_uid, truncate target_uid.
|
||||||
target_uid = target_uid[:254]
|
target_uid = target_uid[:254]
|
||||||
|
time_threshold = timezone.now() - timedelta(minutes=10)
|
||||||
existing_attempts = LoginAttempt.objects.filter(
|
existing_attempts = LoginAttempt.objects.filter(
|
||||||
target_uid=target_uid,
|
target_uid=target_uid,
|
||||||
request_ip=client_ip).order_by('created')
|
request_ip=client_ip,
|
||||||
# TODO: Add logic to group attempts by timeframe, i.e. within 10 minutes
|
last_updated__gt=time_threshold).order_by('created')
|
||||||
if existing_attempts.exists():
|
if existing_attempts.exists():
|
||||||
attempt = existing_attempts.first()
|
attempt = existing_attempts.first()
|
||||||
attempt.attempts += 1
|
attempt.attempts += 1
|
||||||
|
|
Reference in a new issue