Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Re-enable django axes

Roland Geider2f1b53a42221
diff --git a/wger/core/forms.py b/wger/core/forms.py
index 1b29c115b..4d2564f98 100644
--- a/wger/core/forms.py
+++ b/wger/core/forms.py
@@ -19,6 +19,7 @@ from datetime import date
# Django
from django import forms
+from django.contrib.auth import authenticate
from django.contrib.auth.forms import (
AuthenticationForm,
UserCreationForm,
@@ -71,6 +72,28 @@ class UserLoginForm(AuthenticationForm):
)
)
+ def clean(self):
+ """
+ Note this clean method is the same as the one from django/contrib/auth/forms.py,
+ but we pass the request as an explicit request parameter. Otherwise, django
+ axes won't work
+
+ See https://github.com/wger-project/wger/issues/1163
+ """
+ username = self.cleaned_data.get("username")
+ password = self.cleaned_data.get("password")
+
+ if username is not None and password:
+ self.user_cache = authenticate(
+ request=self.request, username=username, password=password
+ )
+ if self.user_cache is None:
+ raise self.get_invalid_login_error()
+ else:
+ self.confirm_login_allowed(self.user_cache)
+
+ return self.cleaned_data
+
class UserPreferencesForm(forms.ModelForm):
first_name = forms.CharField(label=_('First name'), required=False)
@@ -148,7 +171,7 @@ class UserEmailForm(forms.ModelForm):
class Meta:
model = User
- fields = ('email', )
+ fields = ('email',)
def clean_email(self):
"""
diff --git a/wger/settings_global.py b/wger/settings_global.py
index 9d95a95da..c4533b666 100644
--- a/wger/settings_global.py
+++ b/wger/settings_global.py
@@ -20,7 +20,6 @@ import os
import re
from datetime import timedelta
-
"""
This file contains the global settings that don't usually need to be changed.
For a full list of options, visit:
@@ -166,7 +165,7 @@ TEMPLATES = [
'django.template.loaders.app_directories.Loader',
],
'debug':
- False
+ False
},
},
]
@@ -236,7 +235,7 @@ LANGUAGES = (
LANGUAGE_CODE = 'en'
# All translation files are in one place
-LOCALE_PATHS = (os.path.join(SITE_ROOT, 'locale'), )
+LOCALE_PATHS = (os.path.join(SITE_ROOT, 'locale'),)
# Primary keys are AutoFields
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
@@ -287,7 +286,7 @@ CACHES = {
#
# Django Axes
#
-AXES_ENABLED = False
+AXES_ENABLED = True
AXES_FAILURE_LIMIT = 10
AXES_COOLOFF_TIME = timedelta(minutes=30)
AXES_LOCKOUT_TEMPLATE = None
@@ -408,15 +407,15 @@ COMPRESS_ROOT = STATIC_ROOT
# Django Rest Framework
#
REST_FRAMEWORK = {
- 'DEFAULT_PERMISSION_CLASSES': ('wger.utils.permissions.WgerPermission', ),
+ 'DEFAULT_PERMISSION_CLASSES': ('wger.utils.permissions.WgerPermission',),
'DEFAULT_PAGINATION_CLASS':
- 'rest_framework.pagination.LimitOffsetPagination',
+ 'rest_framework.pagination.LimitOffsetPagination',
'PAGE_SIZE':
- 20,
+ 20,
'PAGINATE_BY_PARAM':
- 'limit', # Allow client to override, using `?limit=xxx`.
+ 'limit', # Allow client to override, using `?limit=xxx`.
'TEST_REQUEST_DEFAULT_FORMAT':
- 'json',
+ 'json',
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
@@ -452,7 +451,7 @@ CORS_URLS_REGEX = r'^/api/.*$'
#
# Ignore these URLs if they cause 404
#
-IGNORABLE_404_URLS = (re.compile(r'^/favicon\.ico$'), )
+IGNORABLE_404_URLS = (re.compile(r'^/favicon\.ico$'),)
#
# Password rules