Merge pull request #28 from kencochrane/empty_username_fix

add a fix so that we don't block an empty IP or username
This commit is contained in:
Ken Cochrane 2015-02-02 08:20:53 -05:00
commit dacb37afb8
2 changed files with 8 additions and 1 deletions

View file

@ -21,7 +21,8 @@ from .test import DefenderTestCase, DefenderTransactionTestCase
# Django >= 1.7 compatibility
try:
LOGIN_FORM_KEY = '<form action="/admin/login/" method="post" id="login-form">'
LOGIN_FORM_KEY = '<form action="/admin/login/" method="post"'
' id="login-form">'
ADMIN_LOGIN_URL = reverse('admin:login')
except NoReverseMatch:
ADMIN_LOGIN_URL = reverse('admin:index')

View file

@ -162,6 +162,9 @@ def get_user_attempts(request):
def block_ip(ip):
""" given the ip, block it """
if not ip:
# no reason to continue when there is no ip
return
key = get_ip_blocked_cache_key(ip)
if config.COOLOFF_TIME:
redis_server.set(key, 'blocked', config.COOLOFF_TIME)
@ -171,6 +174,9 @@ def block_ip(ip):
def block_username(username):
""" given the username block it. """
if not username:
# no reason to continue when there is no username
return
key = get_username_blocked_cache_key(username)
if config.COOLOFF_TIME:
redis_server.set(key, 'blocked', config.COOLOFF_TIME)