diff --git a/.travis.yml b/.travis.yml index f782bb9..1a7008c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ python: env: - DJANGO="Django>=1.8,<1.9" - DJANGO="Django>=1.9,<1.10" + - DJANGO="Django --pre" install: - pip install -q $DJANGO diff --git a/axes/apps.py b/axes/apps.py new file mode 100644 index 0000000..cfda3a5 --- /dev/null +++ b/axes/apps.py @@ -0,0 +1,11 @@ +from django import apps + + +class AppConfig(apps.AppConfig): + name = 'axes' + + def ready(self): + from django.contrib.auth import views as auth_views + from axes.decorators import watch_login + + auth_views.login = watch_login(auth_views.login) diff --git a/axes/middleware.py b/axes/middleware.py deleted file mode 100644 index a49b2b0..0000000 --- a/axes/middleware.py +++ /dev/null @@ -1,37 +0,0 @@ -from django.conf import settings -from django.contrib.auth import views as auth_views - -from axes.decorators import watch_login - - -class FailedLoginMiddleware(object): - def __init__(self, *args, **kwargs): - super(FailedLoginMiddleware, self).__init__(*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 - `axes.middleware.FailedLoginMiddleware` and before the django - flatpages middleware. - """ - watched_logins = getattr( - settings, 'AXES_PROTECTED_LOGINS', ( - '/accounts/login/', - ) - ) - - def process_view(self, request, view_func, view_args, view_kwargs): - if request.path in self.watched_logins: - return watch_login(view_func)(request, *view_args, **view_kwargs) - - return None diff --git a/axes/test_settings.py b/axes/test_settings.py index 7a9c965..b8a47d4 100644 --- a/axes/test_settings.py +++ b/axes/test_settings.py @@ -13,7 +13,6 @@ MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'axes.middleware.FailedLoginMiddleware' ) ROOT_URLCONF = 'axes.test_urls' @@ -26,11 +25,33 @@ INSTALLED_APPS = ( 'django.contrib.messages', 'django.contrib.admin', - 'axes', + 'axes.apps.AppConfig', ) +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + SECRET_KEY = 'too-secret-for-test' +USE_I18N = False + +USE_L10N = False + +USE_TZ = False + LOGIN_REDIRECT_URL = '/admin/' AXES_LOGIN_FAILURE_LIMIT = 10 diff --git a/axes/test_urls.py b/axes/test_urls.py index 88ad7e7..13de99f 100644 --- a/axes/test_urls.py +++ b/axes/test_urls.py @@ -1,7 +1,16 @@ -from django.conf.urls import patterns, include +from django.conf.urls import url from django.contrib import admin -urlpatterns = patterns( - '', - (r'^admin/', include(admin.site.urls)), -) +try: + # django < 1.10 + from django.conf.urls import patterns + from django.conf.urls import include + + urlpatterns = patterns( + '', + url(r'^admin/', include(admin.site.urls)), + ) +except ImportError: + urlpatterns = [ + url(r'^admin/', admin.site.urls), + ] diff --git a/project/__init__.py b/project/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/project/app/__init__.py b/project/app/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/project/app/admin.py b/project/app/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/project/app/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/project/app/apps.py b/project/app/apps.py deleted file mode 100644 index 266441b..0000000 --- a/project/app/apps.py +++ /dev/null @@ -1,7 +0,0 @@ -from __future__ import unicode_literals - -from django.apps import AppConfig - - -class AppConfig(AppConfig): - name = 'app' diff --git a/project/app/migrations/__init__.py b/project/app/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/project/app/models.py b/project/app/models.py deleted file mode 100644 index bd4b2ab..0000000 --- a/project/app/models.py +++ /dev/null @@ -1,5 +0,0 @@ -from __future__ import unicode_literals - -from django.db import models - -# Create your models here. diff --git a/project/app/tests.py b/project/app/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/project/app/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/project/app/views.py b/project/app/views.py deleted file mode 100644 index 91ea44a..0000000 --- a/project/app/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. diff --git a/project/settings.py b/project/settings.py deleted file mode 100644 index fde0311..0000000 --- a/project/settings.py +++ /dev/null @@ -1,117 +0,0 @@ -""" -Django settings for project project. - -Generated by 'django-admin startproject' using Django 1.9.7. - -For more information on this file, see -https://docs.djangoproject.com/en/1.9/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.9/ref/settings/ -""" - -import os - -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '^q7^rav7tho&=-$q2c5x%%ukv6hg=#x-%)v4w=d+4pskg-17hy' - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = [] - - -# Application definition - -INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'axes', -] - -MIDDLEWARE_CLASSES = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', - 'axes.middleware.FailedLoginMiddleware', -] - -ROOT_URLCONF = 'project.urls' - -TEMPLATES = [ - { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', - ], - }, - }, -] - -WSGI_APPLICATION = 'project.wsgi.application' - - -# Database -# https://docs.djangoproject.com/en/1.9/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } -} - - -# Password validation -# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators - -AUTH_PASSWORD_VALIDATORS = [ - { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', - }, -] - - -# Internationalization -# https://docs.djangoproject.com/en/1.9/topics/i18n/ - -LANGUAGE_CODE = 'en-us' - -TIME_ZONE = 'UTC' - -USE_I18N = True - -USE_L10N = True - -USE_TZ = True - - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.9/howto/static-files/ - -STATIC_URL = '/static/' diff --git a/project/urls.py b/project/urls.py deleted file mode 100644 index eb75156..0000000 --- a/project/urls.py +++ /dev/null @@ -1,21 +0,0 @@ -"""project URL Configuration - -The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/1.9/topics/http/urls/ -Examples: -Function views - 1. Add an import: from my_app import views - 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') -Class-based views - 1. Add an import: from other_app.views import Home - 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') -Including another URLconf - 1. Import the include() function: from django.conf.urls import url, include - 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) -""" -from django.conf.urls import url -from django.contrib import admin - -urlpatterns = [ - url(r'^admin/', admin.site.urls), -] diff --git a/project/wsgi.py b/project/wsgi.py deleted file mode 100644 index 217cd11..0000000 --- a/project/wsgi.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -WSGI config for project project. - -It exposes the WSGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/ -""" - -import os - -from django.core.wsgi import get_wsgi_application - -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings") - -application = get_wsgi_application()