mirror of
https://github.com/jazzband/django-axes.git
synced 2026-04-17 21:41:01 +00:00
Merge pull request #10 from benkonrath/master
patch for Django timezone support in datetime
This commit is contained in:
commit
4a64812e16
1 changed files with 19 additions and 2 deletions
|
|
@ -16,6 +16,11 @@ from django import template
|
|||
from django.template import RequestContext
|
||||
from django.utils.translation import ugettext_lazy, ugettext as _
|
||||
|
||||
# Need to use django timezone support for datetime if the site is using
|
||||
# timezones
|
||||
if settings.USE_TZ:
|
||||
from django.utils.timezone import utc
|
||||
|
||||
from axes.models import AccessAttempt
|
||||
import axes
|
||||
|
||||
|
|
@ -38,6 +43,17 @@ LOCKOUT_URL = getattr(settings, 'AXES_LOCKOUT_URL', None)
|
|||
VERBOSE = getattr(settings, 'AXES_VERBOSE', True)
|
||||
|
||||
|
||||
def get_current_time():
|
||||
"""
|
||||
Returns the current time setting the django timezone if the site is using
|
||||
timezones.
|
||||
"""
|
||||
if settings.USE_TZ:
|
||||
return datetime.utcnow().replace(tzinfo=utc)
|
||||
else:
|
||||
return datetime.now()
|
||||
|
||||
|
||||
def query2str(items):
|
||||
"""Turns a dictionary into an easy-to-read list of key-value pairs.
|
||||
|
||||
|
|
@ -78,7 +94,8 @@ def get_user_attempt(request):
|
|||
return None
|
||||
|
||||
attempt = attempts[0]
|
||||
if COOLOFF_TIME and attempt.attempt_time + COOLOFF_TIME < datetime.now():
|
||||
current_time = get_current_time()
|
||||
if COOLOFF_TIME and attempt.attempt_time + COOLOFF_TIME < current_time:
|
||||
attempt.delete()
|
||||
return None
|
||||
|
||||
|
|
@ -181,7 +198,7 @@ def check_request(request, login_unsuccessful):
|
|||
attempt.http_accept = request.META.get('HTTP_ACCEPT', '<unknown>')
|
||||
attempt.path_info = request.META.get('PATH_INFO', '<unknown>')
|
||||
attempt.failures_since_start = failures
|
||||
attempt.attempt_time = datetime.now()
|
||||
attempt.attempt_time = get_current_time()
|
||||
attempt.save()
|
||||
log.info('AXES: Repeated login failure by %s. Updating access '
|
||||
'record. Count = %s' %
|
||||
|
|
|
|||
Loading…
Reference in a new issue