django-axes/axes/decorators.py
Aleksi Häkli e69d479f6a
Refactor handlers to a more pluggable format
- Define a base handler API with method signatures
- Move proxy handler to a separate path for importability
- Implement a database handler with clean external dependencies
- Change the authentication backend and decorators to use the authentication backend

This enables clean pluggable authentication backend definitions that users
can override and specialize with e.g. cached handlers in their own packages.

Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-22 19:55:57 +02:00

26 lines
642 B
Python

from functools import wraps
from axes.handlers.proxy import AxesProxyHandler
from axes.utils import get_lockout_response
def axes_dispatch(func):
def inner(request, *args, **kwargs):
if AxesProxyHandler.is_allowed_to_authenticate(request):
return func(request, *args, **kwargs)
return get_lockout_response(request)
return inner
def axes_form_invalid(func):
@wraps(func)
def inner(self, *args, **kwargs):
if AxesProxyHandler.is_allowed_to_authenticate(self.request):
return func(self, *args, **kwargs)
return get_lockout_response(self.request)
return inner