Skip to content

Instantly share code, notes, and snippets.

@kelvan
Created October 22, 2015 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kelvan/3677f859960bb9e7205a to your computer and use it in GitHub Desktop.
Save kelvan/3677f859960bb9e7205a to your computer and use it in GitHub Desktop.
Logout deactivated users
from django.contrib.auth import logout
from django.contrib import messages
from django.utils.translation import ugettext_lazy as _
class LogoutDisabledUserMiddleware:
"""Logout user if it is deactivated
"""
def process_request(self, request):
if request.user.is_authenticated() and not request.user.is_active:
logout(request)
messages.add_message(request, messages.INFO, _('Your account was deactivated'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment