2020-11-23 17:43:50 +00:00
|
|
|
from django.contrib.auth.views import LoginView
|
2017-06-12 23:10:03 +00:00
|
|
|
from django.utils.decorators import method_decorator
|
2014-12-31 01:17:15 +00:00
|
|
|
|
2014-12-31 22:00:45 +00:00
|
|
|
from .decorators import watch_login
|
2014-12-31 01:17:15 +00:00
|
|
|
|
|
|
|
|
|
2020-11-23 17:43:50 +00:00
|
|
|
class FailedLoginMiddleware:
|
2017-06-28 21:09:44 +00:00
|
|
|
""" Failed login middleware """
|
2019-11-15 18:22:14 +00:00
|
|
|
|
2017-06-12 23:10:03 +00:00
|
|
|
patched = False
|
|
|
|
|
|
2020-11-23 17:43:50 +00:00
|
|
|
def __init__(self, get_response):
|
|
|
|
|
self.get_response = get_response
|
|
|
|
|
|
2017-06-12 23:10:03 +00:00
|
|
|
# Watch the auth login.
|
|
|
|
|
# Monkey-patch only once - otherwise we would be recording
|
|
|
|
|
# failed attempts multiple times!
|
|
|
|
|
if not FailedLoginMiddleware.patched:
|
2020-11-23 17:43:50 +00:00
|
|
|
our_decorator = watch_login()
|
|
|
|
|
watch_login_method = method_decorator(our_decorator)
|
|
|
|
|
LoginView.dispatch = watch_login_method(LoginView.dispatch)
|
2017-06-12 23:10:03 +00:00
|
|
|
|
|
|
|
|
FailedLoginMiddleware.patched = True
|
2020-11-23 17:43:50 +00:00
|
|
|
|
|
|
|
|
def __call__(self, request):
|
|
|
|
|
response = self.get_response(request)
|
|
|
|
|
return response
|