mirror of
https://github.com/jazzband/django-axes.git
synced 2026-05-12 09:33:12 +00:00
added ipaddress as a param to the user_locked_out signal; also added a signal reciever for user_logged_out so that we can log when the user logs out in the accessLog table.
This commit is contained in:
parent
2b77673336
commit
4e16a85aed
2 changed files with 28 additions and 3 deletions
|
|
@ -298,7 +298,8 @@ def check_request(request, login_unsuccessful):
|
|||
log.warn('AXES: locked out %s after repeated login attempts.' %
|
||||
(ip_address,))
|
||||
# send signal when someone is locked out.
|
||||
user_locked_out.send(request=request, username=username)
|
||||
user_locked_out.send(request=request, username=username,
|
||||
ip_address=ip_address)
|
||||
|
||||
# if a trusted login has violated lockout, revoke trust
|
||||
for attempt in [a for a in attempts if a.trusted]:
|
||||
|
|
|
|||
|
|
@ -1,3 +1,27 @@
|
|||
from django.dispatch import Signal
|
||||
from django.dispatch import Signal, receiver
|
||||
from django.contrib.auth.signals import user_logged_out
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from axes.models import AccessLog
|
||||
|
||||
user_locked_out = Signal(providing_args=['request', 'username'])
|
||||
# django 1.4 has a new timezone aware now() use if available.
|
||||
try:
|
||||
from django.utils.timezone import now
|
||||
except ImportError:
|
||||
# fall back to none timezone aware now()
|
||||
from datetime import datetime
|
||||
now = datetime.now
|
||||
|
||||
user_locked_out = Signal(providing_args=['request', 'username', 'ip_address'])
|
||||
|
||||
@receiver(user_logged_out)
|
||||
def log_user_lockout(sender, request, user, signal, *args, **kwargs):
|
||||
""" When a user logs out, update the access log"""
|
||||
if not user:
|
||||
return
|
||||
|
||||
access_log = AccessLog.objects.filter(username=user.username,
|
||||
logout_time__isnull=True).order_by("-attempt_time")[0]
|
||||
|
||||
if access_log:
|
||||
access_log.logout_time = now()
|
||||
access_log.save()
|
||||
Loading…
Reference in a new issue