Esempio n. 1
0
 def process_request(self, request):
     # the assumption here is that we will never have an ExtUser for AnonymousUser
     _thread_locals.user = getattr(request, 'user', None)
     if request.user and not request.user.is_anonymous():
         self._set_extuser(request, request.user)
     else:
         request.extuser = None
         # attempt our custom authentication only if regular auth fails
         # (and request.user == anonymousUser
         username, password = get_username_password(request)
         if username and password:
             user = authenticate(username=username, password=password)
             if user is not None:
                 request.user = user
                 self._set_extuser(request, user)
     # do the same for start and end dates.  at some point our views
     # can just start accessing these properties on the request assuming
     # our middleware is running  
     try:
         startdate, enddate = utils.get_dates(request)
         request.startdate = startdate
         request.enddate = enddate
     except Exception:
         request.startdate = None
         request.enddate = None
     return None
Esempio n. 2
0
 def is_authenticated(self, request):
     username, password = get_username_password(request)
     if username and password:
         return self.authfunc(username=username, password=password)
     return False