diff --git a/InvenTree/InvenTree/middleware.py b/InvenTree/InvenTree/middleware.py index 8a2c0b17a4..d68db75de8 100644 --- a/InvenTree/InvenTree/middleware.py +++ b/InvenTree/InvenTree/middleware.py @@ -1,6 +1,9 @@ from django.shortcuts import HttpResponseRedirect from django.urls import reverse_lazy from django.db import connection +from django.shortcuts import redirect +from django.conf import settings +from django.shortcuts import redirect import logging import time import operator @@ -63,8 +66,10 @@ class AuthRequiredMiddleware(object): # No authorization was found for the request if not authorized: - if not request.path_info == reverse_lazy('login') and not request.path_info.startswith('/api/'): + if request.path_info == reverse_lazy('logout'): return HttpResponseRedirect(reverse_lazy('login')) + if not request.path_info == reverse_lazy('login') and not request.path_info.startswith('/api/'): + return redirect('%s?next=%s' % (settings.LOGIN_URL, request.path)) # Code to be executed for each request/response after # the view is called. diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index 797924fd36..30ff234598 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -39,6 +39,9 @@ else: with open(cfg_filename, 'r') as cfg: CONFIG = yaml.safe_load(cfg) +#provide a default login url +LOGIN_URL = "/login" + # Read the autogenerated key-file key_file = open(os.path.join(BASE_DIR, 'secret_key.txt'), 'r') diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index e7530035d6..1220f09ddc 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -102,7 +102,7 @@ urlpatterns = [ url(r'^auth/', include('rest_framework.urls', namespace='rest_framework')), - url(r'^login/', auth_views.LoginView.as_view(), name='login'), + url(r'^login/?', auth_views.LoginView.as_view(), name='login'), url(r'^logout/', auth_views.LogoutView.as_view(template_name='registration/logout.html'), name='logout'), url(r'^settings/', include(settings_urls)),