def email_admins_on_user_locked_out(cache_key, ip_address): """Email admins on user locked out.""" cache = get_cache() key = f"{cache_key}-notified" lockout_email_sent = cache.get(key, False) if not lockout_email_sent: cache.set(key, True, get_cache_timeout()) context = { "ip_address": ip_address, "time": now(), "project_name": settings.PROJECT_NAME, } mail_admins( subject="A lockout has occured", message=render_to_string("axes/lockout_admin_email.txt", context=context), html_message=render_to_string("axes/lockout_admin_email.html", context=context), )
def __init__(self): self.cache = get_cache() self.cache_timeout = get_cache_timeout()
def reset(self, **kwargs): get_cache().delete(make_cache_key_list([kwargs])[0])
def attempt_count(self): cache = get_cache() keys = cache._cache return len(keys)
def tearDown(self): get_cache().clear()