From 395e03803f25386e05821787381f31b908715c57 Mon Sep 17 00:00:00 2001 From: George Lacey Date: Wed, 12 May 2021 11:36:20 +0100 Subject: [PATCH] Add axes support with custom error page --- borgweb/borg/views.py | 4 ++++ borgweb/borgweb/settings.py | 8 ++++++++ borgweb/setup.sh | 2 +- borgweb/templates/error/axes.html | 4 ++++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 borgweb/templates/error/axes.html diff --git a/borgweb/borg/views.py b/borgweb/borg/views.py index 0f0da84..8eb6067 100644 --- a/borgweb/borg/views.py +++ b/borgweb/borg/views.py @@ -126,3 +126,7 @@ def post_location(request): form = LocationForm () return render(request, 'borg/post/location.html', {'form': form}) + + +def axes(request, credentials, *args, **kwargs): + return render(request, 'error/axes.html', {}) diff --git a/borgweb/borgweb/settings.py b/borgweb/borgweb/settings.py index d4d8425..cfc661d 100644 --- a/borgweb/borgweb/settings.py +++ b/borgweb/borgweb/settings.py @@ -22,9 +22,15 @@ DEBUG = True ALLOWED_HOSTS = [] +AXES_LOCKOUT_CALLABLE = "borg.views.axes" # Application definition +AUTHENTICATION_BACKENDS = [ + 'axes.backends.AxesBackend', + 'django.contrib.auth.backends.ModelBackend', +] + INSTALLED_APPS = [ 'borg.apps.BorgConfig', 'django.contrib.admin', @@ -34,6 +40,7 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'compressor', + 'axes', ] MIDDLEWARE = [ @@ -44,6 +51,7 @@ MIDDLEWARE = [ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'axes.middleware.AxesMiddleware', ] ROOT_URLCONF = 'borgweb.urls' diff --git a/borgweb/setup.sh b/borgweb/setup.sh index e93c966..0372722 100644 --- a/borgweb/setup.sh +++ b/borgweb/setup.sh @@ -35,7 +35,7 @@ print_action "Installing pip packages, this may take a while..." # install required pip packages yes | python -m pip install --upgrade wheel -yes | python -m pip install django gunicorn sass django-libsass django_compressor +yes | python -m pip install django gunicorn sass django-libsass django-compressor django-axes print_action "Setting up static files and database" diff --git a/borgweb/templates/error/axes.html b/borgweb/templates/error/axes.html new file mode 100644 index 0000000..a740fd9 --- /dev/null +++ b/borgweb/templates/error/axes.html @@ -0,0 +1,4 @@ +{% extends "error/error.html" %} + +{% block title %}Access Denied{% endblock %} +{% block error_message %}Too many failed login attempts{% endblock %}