django-allauth compatibility
See original GitHub issueFor me django-axes
didn’t work with django-allauth
package by default.
Problem 1:
After some digging in code I’ve made my own apps.py
that monkey patches allauth’s LoginView
the same way as axes does it to django’s LoginView
:
class AppConfig(apps.AppConfig):
name = 'my_app_name'
def ready(self):
from allauth.account.views import LoginView # <-- Just this line is changed
from django.utils.decorators import method_decorator
from axes import signals # we must load signals
from axes.decorators import axes_dispatch
from axes.decorators import axes_form_invalid
LoginView.dispatch = method_decorator(axes_dispatch)(LoginView.dispatch)
LoginView.form_invalid = method_decorator(axes_form_invalid)(LoginView.form_invalid)
It may be useful to either point that out in readme or to modify apps.py
to try to detect allauth and patch it too.
Problem 2:
axes rely on having login id stored under AXES_USERNAME_FORM_FIELD
key both in request.POST and in credentials
arg of user_login_failed
signal. This is not the case with allauth. They allways use login
key in post POST data but it becomes username
key in credentials
dict in signal handler.
When I put AXES_USERNAME_FORM_FIELD='login'
in use with AXES_ONLY_USER_FAILURES=True
it causes empty username go to cache key and therefore locking everybody out when anyone is locked. They all get the same cache key then.
I’m using: django-axes==4.0.1 django-allauth==0.34.0 (note: 0.31.0 didn’t work with my fix either, had to upgrade) django==1.11
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (6 by maintainers)
For now I’ll only paste my solution to Problem 2 mentioned above:
In settings:
AXES_USERNAME_FORM_FIELD = 'login'
In
my_app.forms.py
:And then use this custom form in
urls.py
:Also, Problem 1 might be solved in more elegant way by wrapping the view in
urls.py
as you mentioned in issue #287I hope this helps somebody.
Fixed in #294.