Exemplo n.º 1
0
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),
        )
Exemplo n.º 2
0
 def test_get_cache_timeout_none(self):
     self.assertEqual(get_cache_timeout(), None)
Exemplo n.º 3
0
 def test_get_cache_timeout_integer(self):
     timeout_seconds = float(60 * 60 * 3)
     self.assertEqual(get_cache_timeout(), timeout_seconds)
Exemplo n.º 4
0
 def test_get_cache_timeout_timedelta(self):
     self.assertEqual(get_cache_timeout(), 420)
Exemplo n.º 5
0
 def __init__(self):
     self.cache = get_cache()
     self.cache_timeout = get_cache_timeout()
Exemplo n.º 6
0
 def __init__(self):
     self.cache = get_cache()
     self.cache_timeout = get_cache_timeout()
Exemplo n.º 7
0
 def test_get_cache_timeout_none(self):
     self.assertEqual(get_cache_timeout(), None)
Exemplo n.º 8
0
 def test_get_cache_timeout_timedelta(self):
     self.assertEqual(get_cache_timeout(), 420)
Exemplo n.º 9
0
 def test_get_cache_timeout_integer(self):
     timeout_seconds = float(60 * 60 * 3)
     self.assertEqual(get_cache_timeout(), timeout_seconds)