mirror of
https://github.com/jazzband/django-defender.git
synced 2026-05-17 20:11:10 +00:00
Merge branch 'master' into new-admin
This commit is contained in:
commit
b50b05f1d2
6 changed files with 0 additions and 26 deletions
|
|
@ -274,8 +274,6 @@ locked out.
|
||||||
* ``DEFENDER_REDIS_URL``: String: the redis url for defender.
|
* ``DEFENDER_REDIS_URL``: String: the redis url for defender.
|
||||||
Default: ``redis://localhost:6379/0``
|
Default: ``redis://localhost:6379/0``
|
||||||
(Example with password: ``redis://:mypassword@localhost:6379/0``)
|
(Example with password: ``redis://:mypassword@localhost:6379/0``)
|
||||||
* ``DEFENDER_PROTECTED_LOGINS``: Tuple: Used by ``ViewDecoratorMiddleware`` to decide
|
|
||||||
which login urls need protecting. Default: ``('/accounts/login/',)``
|
|
||||||
* ``DEFENDER_USE_CELERY``: Boolean: If you want to use Celery to store the login
|
* ``DEFENDER_USE_CELERY``: Boolean: If you want to use Celery to store the login
|
||||||
attempt to the database, set to True. If False, it is saved inline.
|
attempt to the database, set to True. If False, it is saved inline.
|
||||||
Default: ``False``
|
Default: ``False``
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,4 @@ USERNAME_FORM_FIELD = get_setting('DEFENDER_USERNAME_FORM_FIELD', 'username')
|
||||||
LOCKOUT_URL = get_setting('DEFENDER_LOCKOUT_URL')
|
LOCKOUT_URL = get_setting('DEFENDER_LOCKOUT_URL')
|
||||||
|
|
||||||
|
|
||||||
PROTECTED_LOGINS = get_setting('DEFENDER_PROTECTED_LOGINS',
|
|
||||||
('/accounts/login/',))
|
|
||||||
|
|
||||||
USE_CELERY = get_setting('DEFENDER_USE_CELERY', False)
|
USE_CELERY = get_setting('DEFENDER_USE_CELERY', False)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
from django.contrib.auth import views as auth_views
|
from django.contrib.auth import views as auth_views
|
||||||
|
|
||||||
from .decorators import watch_login
|
from .decorators import watch_login
|
||||||
from .config import PROTECTED_LOGINS
|
|
||||||
|
|
||||||
|
|
||||||
class FailedLoginMiddleware(object):
|
class FailedLoginMiddleware(object):
|
||||||
|
|
@ -10,20 +9,3 @@ class FailedLoginMiddleware(object):
|
||||||
|
|
||||||
# watch the auth login
|
# watch the auth login
|
||||||
auth_views.login = watch_login(auth_views.login)
|
auth_views.login = watch_login(auth_views.login)
|
||||||
|
|
||||||
|
|
||||||
class ViewDecoratorMiddleware(object):
|
|
||||||
"""
|
|
||||||
When the django_axes middleware is installed, by default it watches the
|
|
||||||
django.auth.views.login.
|
|
||||||
This middleware allows adding protection to other views without the need
|
|
||||||
to change any urls or dectorate them manually.
|
|
||||||
Add this middleware to your MIDDLEWARE settings after
|
|
||||||
`defender.middleware.FailedLoginMiddleware` and before the django
|
|
||||||
flatpages middleware.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def process_view(self, request, view_func, view_args, view_kwargs):
|
|
||||||
if request.path in PROTECTED_LOGINS:
|
|
||||||
return watch_login(view_func)(request, *view_args, **view_kwargs)
|
|
||||||
return None
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ MIDDLEWARE_CLASSES = (
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||||
'defender.middleware.FailedLoginMiddleware',
|
'defender.middleware.FailedLoginMiddleware',
|
||||||
'defender.middleware.ViewDecoratorMiddleware',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
ROOT_URLCONF = 'defender.test_urls'
|
ROOT_URLCONF = 'defender.test_urls'
|
||||||
|
|
|
||||||
|
|
@ -501,7 +501,6 @@ class AccessAttemptTest(DefenderTestCase):
|
||||||
from .admin import AccessAttemptAdmin
|
from .admin import AccessAttemptAdmin
|
||||||
AccessAttemptAdmin
|
AccessAttemptAdmin
|
||||||
|
|
||||||
@patch('defender.config.PROTECTED_LOGINS', (ADMIN_LOGIN_URL, ))
|
|
||||||
def test_decorator_middleware(self):
|
def test_decorator_middleware(self):
|
||||||
# because watch_login is called twice in this test (once by the
|
# because watch_login is called twice in this test (once by the
|
||||||
# middleware and once by the decorator) we have half as many attempts
|
# middleware and once by the decorator) we have half as many attempts
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ MIDDLEWARE_CLASSES = (
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||||
'defender.middleware.FailedLoginMiddleware',
|
'defender.middleware.FailedLoginMiddleware',
|
||||||
'defender.middleware.ViewDecoratorMiddleware',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
ROOT_URLCONF = 'defender.test_urls'
|
ROOT_URLCONF = 'defender.test_urls'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue