Advertisement
Guest User

ShawnMilo

a guest
Oct 15th, 2009
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. from django.http import HttpResponseRedirect
  2.  
  3. class LoginChecksMiddleware(object):
  4.    
  5.     """
  6.    A user has to be logged in to access
  7.    any screen other than the login screen
  8.    and password reset screen.
  9.    
  10.    A logged-in user must have changed their
  11.    password within the required period.
  12.    """
  13.    
  14.     def process_request(self, request):
  15.        
  16.         if request.user.is_anonymous():
  17.            
  18.             #if they're trying to log in, let them
  19.             if request.META['PATH_INFO'].startswith('/login/') or \
  20.                 request.META['PATH_INFO'].startswith('/password_reset') or \
  21.                 request.META['PATH_INFO'].startswith('/reset/'):
  22.                
  23.                 return None
  24.                
  25.             #redirect to login
  26.             return HttpResponseRedirect('/login/')
  27.         else:
  28.             #if they're trying to go to the password_change
  29.             #page, let them in any case
  30.             if request.META['PATH_INFO'] == '/password_change/':
  31.                 return None
  32.  
  33.             #if password is expired, redirect
  34.             if request.user.get_profile().password_is_expired():
  35.                 return HttpResponseRedirect('/password_change/')
  36.        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement