mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Updated middleware for Django 1.10
This commit is contained in:
@ -117,7 +117,8 @@ INSTALLED_APPS = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Middleware
|
# Middleware
|
||||||
MIDDLEWARE_CLASSES = (
|
MIDDLEWARE = (
|
||||||
|
'debug_toolbar.middleware.DebugToolbarMiddleware',
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
'django.middleware.common.CommonMiddleware',
|
'django.middleware.common.CommonMiddleware',
|
||||||
'django.middleware.csrf.CsrfViewMiddleware',
|
'django.middleware.csrf.CsrfViewMiddleware',
|
||||||
|
@ -6,14 +6,18 @@ BASE_PATH = getattr(settings, 'BASE_PATH', False)
|
|||||||
LOGIN_REQUIRED = getattr(settings, 'LOGIN_REQUIRED', False)
|
LOGIN_REQUIRED = getattr(settings, 'LOGIN_REQUIRED', False)
|
||||||
|
|
||||||
|
|
||||||
class LoginRequiredMiddleware:
|
class LoginRequiredMiddleware(object):
|
||||||
"""
|
"""
|
||||||
If LOGIN_REQUIRED is True, redirect all non-authenticated users to the login page.
|
If LOGIN_REQUIRED is True, redirect all non-authenticated users to the login page.
|
||||||
"""
|
"""
|
||||||
def process_request(self, request):
|
def __init__(self, get_response):
|
||||||
|
self.get_response = get_response
|
||||||
|
|
||||||
|
def __call__(self, request):
|
||||||
if LOGIN_REQUIRED and not request.user.is_authenticated():
|
if LOGIN_REQUIRED and not request.user.is_authenticated():
|
||||||
# Redirect unauthenticated requests to the login page. API requests are exempt from redirection as the API
|
# Redirect unauthenticated requests to the login page. API requests are exempt from redirection as the API
|
||||||
# performs its own authentication.
|
# performs its own authentication.
|
||||||
api_path = '/{}api/'.format(BASE_PATH)
|
api_path = '/{}api/'.format(BASE_PATH)
|
||||||
if not request.path_info.startswith(api_path) and request.path_info != settings.LOGIN_URL:
|
if not request.path_info.startswith(api_path) and request.path_info != settings.LOGIN_URL:
|
||||||
return HttpResponseRedirect('{}?next={}'.format(settings.LOGIN_URL, request.path_info))
|
return HttpResponseRedirect('{}?next={}'.format(settings.LOGIN_URL, request.path_info))
|
||||||
|
return self.get_response(request)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
cffi>=1.8
|
cffi>=1.8
|
||||||
cryptography==1.4
|
cryptography==1.4
|
||||||
Django==1.10
|
Django>=1.10
|
||||||
django-debug-toolbar==1.4
|
django-debug-toolbar>=1.6
|
||||||
django-filter==0.13.0
|
django-filter==0.13.0
|
||||||
django-rest-swagger==0.3.10
|
django-rest-swagger==0.3.10
|
||||||
django-tables2==1.2.1
|
django-tables2==1.2.1
|
||||||
@ -15,5 +15,5 @@ paramiko==2.0.0
|
|||||||
psycopg2==2.6.1
|
psycopg2==2.6.1
|
||||||
py-gfm==0.1.3
|
py-gfm==0.1.3
|
||||||
pycrypto==2.6.1
|
pycrypto==2.6.1
|
||||||
sqlparse==0.1.19
|
sqlparse>=0.2
|
||||||
xmltodict==0.10.2
|
xmltodict==0.10.2
|
||||||
|
Reference in New Issue
Block a user