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