bgneal@215: """Common middleware for the entire project.""" bgneal@215: from django.contrib.auth import logout bgneal@215: bgneal@215: class InactiveUserMiddleware(object): bgneal@215: """ bgneal@215: This middleware ensures users with is_active set to False get their bgneal@215: session destroyed and are treated as logged out. bgneal@215: This middleware should come after the 'django.contrib.auth.middleware. bgneal@215: AuthenticationMiddleware' in settings.py. bgneal@215: Idea taken from: http://djangosnippets.org/snippets/1105/ bgneal@215: """ bgneal@215: bgneal@215: def process_request(self, request): bgneal@215: if request.user.is_authenticated() and not request.user.is_active: bgneal@215: logout(request) bgneal@215: