Skip to content

Commit

Permalink
Merge branch 'master' of github.com:brutasse/django-ratelimit-backend
Browse files Browse the repository at this point in the history
  • Loading branch information
brutasse committed Mar 16, 2017
2 parents 4c3e267 + 192303f commit 1ced96c
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ sudo: false
env:
- TOXENV=py27-django18
- TOXENV=py27-django19
- TOXENV=py27-django110
- TOXENV=py27-django111
- TOXENV=py33-django18
- TOXENV=py34-django18
- TOXENV=py34-django19
- TOXENV=py34-django110
- TOXENV=py34-django111
- TOXENV=py35-django19
- TOXENV=py35-django110
- TOXENV=py35-django111
- TOXENV=docs
- TOXENV=lint
install:
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ customized.

* Licence: BSD

* Compatibility: Django 1.4 and greater
* Compatibility: Django 1.8 and greater

* Documentation: http://django-ratelimit-backend.rtfd.org
* Documentation: https://django-ratelimit-backend.readthedocs.io

* Code: https://github.com/brutasse/django-ratelimit-backend

Expand Down
4 changes: 3 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ Get involved, submit issues and pull requests on the `code repository`_!
Changes
-------

* **1.0.1** (TBA):
* **1.1** (TBA):

* Exclude tests from being installed from the wheel file.

* Add support for Django 1.10 and 1.11.

* **1.0** (2015-07-10):

* Silence warnings with Django 1.8.
Expand Down
2 changes: 2 additions & 0 deletions ratelimitbackend/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ def login(self, request, extra_context=None):
'template_name': self.login_template or 'admin/login.html',
}
return login(request, **defaults)


site = RateLimitAdminSite()
7 changes: 4 additions & 3 deletions ratelimitbackend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class RateLimitMixin(object):
requests = 30
username_key = 'username'

def authenticate(self, **kwargs):
request = kwargs.pop('request', None)
def authenticate(self, request=None, **kwargs):
username = kwargs[self.username_key]
if request is not None:
counts = self.get_counters(request)
Expand All @@ -36,7 +35,9 @@ def authenticate(self, **kwargs):
warnings.warn(u"No request passed to the backend, unable to "
u"rate-limit. Username was '%s'" % username,
stacklevel=2)
user = super(RateLimitMixin, self).authenticate(**kwargs)
user = super(RateLimitMixin, self).authenticate(
request=request, **kwargs
)
if user is None and request is not None:
logger.info(
u"Login failed: username '{0}', IP {1}".format(
Expand Down
6 changes: 5 additions & 1 deletion ratelimitbackend/middleware.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from django.http import HttpResponseForbidden
try:
from django.utils.deprecation import MiddlewareMixin
except ImportError: # Django < 1.10
MiddlewareMixin = object

from .exceptions import RateLimitException


class RateLimitMiddleware(object):
class RateLimitMiddleware(MiddlewareMixin):
"""
Handles exceptions thrown by rate-limited login attepmts.
"""
Expand Down
6 changes: 5 additions & 1 deletion runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import sys

import django
from django.conf import settings
from django.test.runner import DiscoverRunner
from django.utils.functional import empty
Expand Down Expand Up @@ -44,7 +45,7 @@ def setup_test_environment():
},
},
"ROOT_URLCONF": "tests.urls",
"MIDDLEWARE_CLASSES": middleware_classes,
"MIDDLEWARE": middleware_classes,
"INSTALLED_APPS": apps,
"SITE_ID": 1,
"AUTHENTICATION_BACKENDS": (
Expand Down Expand Up @@ -76,6 +77,9 @@ def setup_test_environment():
}],
}

if django.VERSION < (1, 10):
settings_dict["MIDDLEWARE_CLASSES"] = settings_dict["MIDDLEWARE"]

# set up settings for running tests for all apps
settings.configure(**settings_dict)
from django import setup
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
'Framework :: Django :: 1.8',
'Framework :: Django :: 1.9',
'Framework :: Django :: 1.10',
'Framework :: Django :: 1.11',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Natural Language :: English',
Expand Down
2 changes: 1 addition & 1 deletion tests/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def key(self, request, dt):


class CustomBackend(ModelBackend):
def authenticate(self, token=None, secret=None):
def authenticate(self, request=None, token=None, secret=None):
try:
user = User.objects.get(username=token)
if user.check_password(secret):
Expand Down
5 changes: 4 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
envlist =
py{27,33,34}-django18,
py{27,34,35}-django19,
py{27,34,35}-django110,
py{27,34,35}-django111,
docs, lint

[testenv]
commands = python -Wall setup.py test
deps =
django18: Django>=1.8,<1.9
django19: Django>=1.9,<1.10
install_command = pip install --no-binary Django {opts} {packages}
django110: Django>=1.10,<1.11
django111: Django>=1.11a1,<2.0

[testenv:docs]
changedir = docs
Expand Down

0 comments on commit 1ced96c

Please sign in to comment.