1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00
2016-10-13 16:12:27 -04:00

16 lines
543 B
Python

from django.http import HttpResponseRedirect
from django.conf import settings
LOGIN_REQUIRED = getattr(settings, 'LOGIN_REQUIRED', False)
class LoginRequiredMiddleware:
"""
If LOGIN_REQUIRED is True, redirect all non-authenticated users to the login page.
"""
def process_request(self, request):
if LOGIN_REQUIRED and not request.user.is_authenticated():
if request.path_info != settings.LOGIN_URL:
return HttpResponseRedirect('{}?next={}'.format(settings.LOGIN_URL, request.path_info))