Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. from django.conf import settings
  2. from django.shortcuts import redirect
  3.  
  4.  
  5. EXEMPT_URLS = [settings.LOGIN_URL.lstrip('/')]
  6. if hasattr(settings, 'LOGIN_EXEMPT_URLS'):
  7. EXEMPT_URLS += [url for url in settings.LOGIN_EXEMPT_URLS]
  8.  
  9.  
  10. class LoginRequiredMiddleware:
  11.  
  12. def __init__(self, get_response):
  13. self.get_response = get_response
  14.  
  15. def __call__(self, request):
  16. response = self.get_response(request)
  17. return response
  18.  
  19. def process_view(self, request, view_func, view_args, view_kwargs):
  20. assert hasattr(request, 'user')
  21. path = request.path_info.lstrip('/')
  22. print(path)
  23.  
  24. if not request.user.is_authenticated:
  25. if path not in EXEMPT_URLS:
  26. return redirect(settings.LOGIN_URL)
  27.  
  28. LOGIN_REDIRECT_URL = '/accounts/'
  29.  
  30. LOGIN_URL = '/accounts/login/'
  31.  
  32. LOGIN_EXEMPT_URLS = (
  33.  
  34. r'^register/$',
  35.  
  36. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement