Example #1
0
    def process_response(self, request, response):
        if isinstance(response, (HttpResponseForbidden,
                                 HttpResponseNotAllowed)):
            if request.user.is_authenticated():
                return error_page(request, 500, status=response.status_code)
            else:
                return HttpResponseRedirect(reverse('login'))

        return response
Example #2
0
 def process_response(self, request, response):
     if isinstance(response,
                   (HttpResponseForbidden, HttpResponseNotAllowed)):
         if request.user.is_authenticated():
             log.debug('Permission denied middleware, user was '
                       'authenticated, sending 500')
             return error_page(request, 500, status=response.status_code)
         else:
             if isinstance(response, (HttpResponseForbidden)):
                 log.debug('Response was forbidden')
             elif isinstance(response, (HttpResponseNotAllowed)):
                 log.debug('Response was not allowed')
             log.debug('Permission denied middleware, redirecting home')
             return HttpResponseRedirect(reverse('home'))
     return response
Example #3
0
 def process_response(self, request, response):
     if isinstance(response, (HttpResponseForbidden,
                              HttpResponseNotAllowed)):
         if request.user.is_authenticated():
             log.info('Permission denied middleware, user was '
                      'authenticated, sending 500')
             return error_page(request, 500, status=response.status_code)
         else:
             if isinstance(response, (HttpResponseForbidden)):
                 log.info('Response was forbidden')
             elif isinstance(response, (HttpResponseNotAllowed)):
                 log.info('Response was not allowed')
             log.info('Permission denied middleware, redirecting home')
             return HttpResponseRedirect(reverse('home'))
     return response