Skip to content

Commit

Permalink
cleanup the boolean logic around is_already_locked()
Browse files Browse the repository at this point in the history
  • Loading branch information
kencochrane committed Oct 23, 2015
1 parent 6e2ea2b commit 6b91730
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions defender/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,28 +280,13 @@ def is_already_locked(request):
username = request.POST.get(config.USERNAME_FORM_FIELD, None)
user_blocked = REDIS_SERVER.get(get_username_blocked_cache_key(username))

if config.DISABLE_IP_LOCKOUT:
# if DISABLE_IP_LOCKOUT is turned on, then return user_blocked
# result, since we don't care about ip at this point.
return user_blocked

if config.LOCKOUT_BY_IP_USERNAME:
LOG.info("Block by ip & username")
if ip_blocked and user_blocked:
# if both this IP and this username are present the request is
# blocked
return True

else:
if ip_blocked:
# short circuit no need to check username if ip is already blocked.
return True

if user_blocked:
return True
# if both this IP and this username are present the request is
# blocked
return ip_blocked and user_blocked

# if the username nor ip is blocked, the request is not blocked
return False
return ip_blocked or user_blocked


def check_request(request, login_unsuccessful):
Expand Down

0 comments on commit 6b91730

Please sign in to comment.