Skip to content

Commit

Permalink
Merge branch 'master' into new-admin
Browse files Browse the repository at this point in the history
  • Loading branch information
kencochrane committed Jan 29, 2015
2 parents 12698d7 + df09c32 commit b50b05f
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 26 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,6 @@ locked out.
* ``DEFENDER_REDIS_URL``: String: the redis url for defender.
Default: ``redis://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
attempt to the database, set to True. If False, it is saved inline.
Default: ``False``
Expand Down
3 changes: 0 additions & 3 deletions defender/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,4 @@ def get_setting(variable, default=None):
LOCKOUT_URL = get_setting('DEFENDER_LOCKOUT_URL')


PROTECTED_LOGINS = get_setting('DEFENDER_PROTECTED_LOGINS',
('/accounts/login/',))

USE_CELERY = get_setting('DEFENDER_USE_CELERY', False)
18 changes: 0 additions & 18 deletions defender/middleware.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.contrib.auth import views as auth_views

from .decorators import watch_login
from .config import PROTECTED_LOGINS


class FailedLoginMiddleware(object):
Expand All @@ -10,20 +9,3 @@ def __init__(self, *args, **kwargs):

# watch the auth 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
1 change: 0 additions & 1 deletion defender/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'defender.middleware.FailedLoginMiddleware',
'defender.middleware.ViewDecoratorMiddleware',
)

ROOT_URLCONF = 'defender.test_urls'
Expand Down
1 change: 0 additions & 1 deletion defender/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,6 @@ def test_admin(self):
from .admin import AccessAttemptAdmin
AccessAttemptAdmin

@patch('defender.config.PROTECTED_LOGINS', (ADMIN_LOGIN_URL, ))
def test_decorator_middleware(self):
# because watch_login is called twice in this test (once by the
# middleware and once by the decorator) we have half as many attempts
Expand Down
1 change: 0 additions & 1 deletion defender/travis_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'defender.middleware.FailedLoginMiddleware',
'defender.middleware.ViewDecoratorMiddleware',
)

ROOT_URLCONF = 'defender.test_urls'
Expand Down

0 comments on commit b50b05f

Please sign in to comment.