Django Library Users
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

signals.py 1.0KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import logging
  2. from django.contrib.auth.signals import user_logged_in, user_logged_out, user_login_failed
  3. from django.dispatch import receiver
  4. log = logging.getLogger('AUTH')
  5. @receiver(user_logged_in)
  6. def user_logged_in_callback(sender, request, user, **kwargs):
  7. # to cover more complex cases:
  8. # http://stackoverflow.com/questions/4581789/how-do-i-get-user-ip-address-in-django
  9. ip = request.META.get('REMOTE_ADDR')
  10. log.info('Accepted password for {user} from {ip}'.format(
  11. user=user,
  12. ip=ip
  13. ))
  14. @receiver(user_logged_out)
  15. def user_logged_out_callback(sender, request, user, **kwargs):
  16. ip = request.META.get('REMOTE_ADDR')
  17. log.debug('Disconnected from user {user} {ip}'.format(
  18. user=user,
  19. ip=ip
  20. ))
  21. @receiver(user_login_failed)
  22. def user_login_failed_callback(sender, request, credentials, **kwargs):
  23. ip = request.META.get('REMOTE_ADDR')
  24. log.warning('Failed password for {user} from {ip}'.format(
  25. user=credentials.get('username'),
  26. ip=ip
  27. ))