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 test_get_cache_timeout_none(self): self.assertEqual(get_cache_timeout(), None)
def test_get_cache_timeout_integer(self): timeout_seconds = float(60 * 60 * 3) self.assertEqual(get_cache_timeout(), timeout_seconds)
def test_get_cache_timeout_timedelta(self): self.assertEqual(get_cache_timeout(), 420)
def __init__(self): self.cache = get_cache() self.cache_timeout = get_cache_timeout()