I’ve been struggling to include django-axes into a project where I’m using a custom User model. Finally, I got this almost working. I say “almost” because none errors are shown, but unfortunately django-axes is not catching failed login attempts.
In fact, it is showing in the admin that the user got logged (and, therefore, the user is never logout). I think I'm getting exactly the same problem indicated here: Django-axes not working with custom login view
I’ll show you some parts of my code, so maybe you could shed some light into this issue. THANKS IN ADVANCE
urls.py
from axes.decorators import watch_login
from apps.main.views import userLogin
urlpatterns = patterns(‘',
url(r'^login/$', watch_login(userLogin), name="login"),
views.py
from axes.decorators import watch_login
@watch_login
def userLogin(request):
if request.method == "POST":
if 'login_form' in request.POST:
username = request.POST.get('username', '')
password = request.POST.get('password', '')
user = authenticate(username=username, password=password)
if user is not None: # The user exists, credentials OK
if user.is_active:
login(request, user) # Log the user
if not request.POST.get('rememberUser', None):
request.session.set_expiry(3600)
else:
return redirect('users_app:disabled_account')
else:
return redirect('users_app:login_failed')
return redirect('main_app:index')
def LogOut(request):
logout(request)
return redirect('/‘)
class IncorrectLoginView(TemplateView):
template_name = 'users/login_failed.html'
base.py
MIDDLEWARE_CLASES = (
'da_tracker.middleware.TrackerMiddleware',
)