Ticket #5612: login_logout_signals.diff

File login_logout_signals.diff, 1.4 KB (added by pterk, 8 years ago)
  • core/signals.py

     
    11request_started = object()
    22request_finished = object()
    33got_request_exception = object()
     4
     5user_logged_in = object()
     6user_logged_out = object()
  • contrib/auth/__init__.py

     
    11import datetime
    22from django.core.exceptions import ImproperlyConfigured
     3from django.core import signals
     4from django.dispatch import dispatcher
    35
    46SESSION_KEY = '_auth_user_id'
    57BACKEND_SESSION_KEY = '_auth_user_backend'
     
    5759    request.session[BACKEND_SESSION_KEY] = user.backend
    5860    if hasattr(request, 'user'):
    5961        request.user = user
     62    dispatcher.send(signal=signals.user_logged_in, request=request)
    6063
    6164def logout(request):
    6265    """
     
    7174    except KeyError:
    7275        pass
    7376    if hasattr(request, 'user'):
     77        # Dispatch the signal before it is reset to AnonymousUser so
     78        # the receivers have a chance to find out *who* logged out
     79        dispatcher.send(signal=signals.user_logged_out, request=request)
    7480        from django.contrib.auth.models import AnonymousUser
    7581        request.user = AnonymousUser()
    7682
Back to Top