Merge pull request #782 from andyseracuse/redirect-after-login

after a login redirect and a successful login, the user is now redirected to the originally desired url
This commit is contained in:
Oliver 2020-05-04 08:49:13 +10:00 committed by GitHub
commit 461d694cf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View File

@ -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.

View File

@ -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')

View File

@ -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)),