django-axes/axes/apps.py
Aleksi Häkli e69d479f6a
Refactor handlers to a more pluggable format
- Define a base handler API with method signatures
- Move proxy handler to a separate path for importability
- Implement a database handler with clean external dependencies
- Change the authentication backend and decorators to use the authentication backend

This enables clean pluggable authentication backend definitions that users
can override and specialize with e.g. cached handlers in their own packages.

Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-22 19:55:57 +02:00

47 lines
1.2 KiB
Python

from logging import getLogger
from django import apps
from axes import get_version
from axes.conf import settings
from axes.handlers.proxy import AxesProxyHandler
log = getLogger(settings.AXES_LOGGER)
class AppConfig(apps.AppConfig):
name = 'axes'
logging_initialized = False
@classmethod
def initialize(cls):
"""
Initialize Axes logging and show version information.
This method is re-entrant and can be called multiple times.
It displays version information exactly once at application startup.
"""
if cls.logging_initialized:
return
cls.logging_initialized = True
if not settings.AXES_VERBOSE:
return
log.info('AXES: BEGIN LOG')
log.info('AXES: Using django-axes %s', get_version())
if settings.AXES_ONLY_USER_FAILURES:
log.info('AXES: blocking by username only.')
elif settings.AXES_LOCK_OUT_BY_COMBINATION_USER_AND_IP:
log.info('AXES: blocking by combination of username and IP.')
else:
log.info('AXES: blocking by IP only.')
def ready(self):
self.initialize()
AxesProxyHandler.initialize()
from axes import signals # noqa