Ticket #5612: login_logout_signals_r10823.diff

File login_logout_signals_r10823.diff, 1.6 KB (added by JohnDoe, 6 years ago)
  • django/contrib/auth/__init__.py

     
    11import datetime
    22from django.core.exceptions import ImproperlyConfigured
    33from django.utils.importlib import import_module
     4from django.contrib.auth import signals
    45
    56SESSION_KEY = '_auth_user_id'
    67BACKEND_SESSION_KEY = '_auth_user_backend'
     
    5253    if user is None:
    5354        user = request.user
    5455    # TODO: It would be nice to support different login methods, like signed cookies.
     56    signals.user_logged_in.send(sender=None, request=request, user=user)
    5557    user.last_login = datetime.datetime.now()
    5658    user.save()
    5759
     
    7577    """
    7678    request.session.flush()
    7779    if hasattr(request, 'user'):
     80        # Dispatch the signal before it is reset to AnonymousUser so
     81        # the receivers have a chance to find out *who* logged out
     82        signals.user_logged_out.send(sender=None, request=request)
    7883        from django.contrib.auth.models import AnonymousUser
    7984        request.user = AnonymousUser()
    8085
  • django/contrib/auth/signals.py

     
     1import django.dispatch
     2
     3user_logged_in = django.dispatch.Signal(providing_args=['request', 'user'])
     4user_logged_out = django.dispatch.Signal(providing_args=['request',])
     5 No newline at end of file
Back to Top