mirror of
https://github.com/jazzband/django-defender.git
synced 2026-03-16 22:10:32 +00:00
Fix an issue detected by tests: clear redis cache upon block reset
This commit is contained in:
parent
394f89b4e0
commit
9bcd62aa2c
1 changed files with 23 additions and 1 deletions
|
|
@ -12,7 +12,11 @@ from django.utils.module_loading import import_string
|
|||
|
||||
from .connection import get_redis_connection
|
||||
from . import config
|
||||
from .data import get_approx_account_lockouts_from_login_attempts, store_login_attempt
|
||||
from .data import (
|
||||
get_approx_account_lockouts_from_login_attempts,
|
||||
get_approx_lockouts_cache_key,
|
||||
store_login_attempt,
|
||||
)
|
||||
from .signals import (
|
||||
send_username_block_signal,
|
||||
send_ip_block_signal,
|
||||
|
|
@ -331,6 +335,12 @@ def unblock_ip(ip_address, pipe=None):
|
|||
pipe.execute()
|
||||
send_ip_unblock_signal(ip_address)
|
||||
|
||||
redis_cache_key = get_approx_lockouts_cache_key(ip_address, None)
|
||||
|
||||
if redis_cache_key is not None:
|
||||
redis_client = get_redis_connection()
|
||||
redis_client.delete(redis_cache_key)
|
||||
|
||||
|
||||
def unblock_username(username, pipe=None):
|
||||
""" unblock the given Username """
|
||||
|
|
@ -345,6 +355,12 @@ def unblock_username(username, pipe=None):
|
|||
pipe.execute()
|
||||
send_username_unblock_signal(username)
|
||||
|
||||
redis_cache_key = get_approx_lockouts_cache_key(None, username)
|
||||
|
||||
if redis_cache_key is not None:
|
||||
redis_client = get_redis_connection()
|
||||
redis_client.delete(redis_cache_key)
|
||||
|
||||
|
||||
def reset_failed_attempts(ip_address=None, username=None):
|
||||
""" reset the failed attempts for these ip's and usernames
|
||||
|
|
@ -357,6 +373,12 @@ def reset_failed_attempts(ip_address=None, username=None):
|
|||
unblock_ip(ip_address, pipe=pipe)
|
||||
unblock_username(username, pipe=pipe)
|
||||
|
||||
redis_cache_key = get_approx_lockouts_cache_key(ip_address, username)
|
||||
|
||||
if redis_cache_key is not None:
|
||||
redis_client = get_redis_connection()
|
||||
redis_client.delete(redis_cache_key)
|
||||
|
||||
pipe.execute()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue