* Use redis cache in `get_approx_account_lockouts_from_login_attempts`
* use django_redis in ci
* Add `django_redis` and `redis` to requirements.txt
* Fix an issue detected by tests: clear redis cache upon block reset
* Remove the unnecessary `if`
* Use redis parse_url method instead of a custom one
The custom method defined here has no real advantage
- the redis lib implements it better and have support for many use cases
- maintaining this implementation is error-prone and unnecessary work for overworked open-source contributors :)
Especially, when you want to pass query parameters here, they are not supported (for eg a custom certificate authority)
* remove test about url parsing
* remove unused imports
* FIX: if special character in redis password, we can set DEFENDER_REDIS_PASSWORD_QUOTE to True, and use quote password
* MOD:add test cases with password_quota = True
* Add `DEFENDER_GET_USERNAME_FROM_REQUEST_PATH` setting
This setting allow to override default `get_username_from_request`
function.
* Add `get_username` argument to `watch_login`
To be able to propagate this argument to other utils functions calls
* Minor code-style fixes
* Add example of use of `DEFENDER_GET_USERNAME_FROM_REQUEST_PATH` setting
* Update docs
* Only use the username if it is actually provided
* Test that unspecified usernames cannot be blocked
* Added test to prevent Coveralls from complaining about a coverage regression.
* replace django.core.urlresolvers with django.urls to appeace Django2.0 deprecations
* add try except block around imports for older version support
* add correct django version in setup.py install_reqs
* Cleanup the code to remove lint warnings
Signed-off-by: Ken Cochrane <kencochrane@gmail.com>
* Fixed typo
Signed-off-by: Ken Cochrane <kencochrane@gmail.com>
This fixes bug #GH76 where an exception like
```
Reverse for 'defender_unblock_username_view' with arguments '(u'user+test@domain.tld',)' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'admin/defender/blocks/username/(?P[A-Za-z0-9-._@]+)/unblock$']
```
was raised when trying to access the `/admin/defender/blocks/` URL when a user with a plus sign had been locked out.
The `is_already_locked` method assumes how the username is stored in the
request. This patch adds helpers that don't to allow for more flexible
implementation.