annotate antispam/receivers.py @ 921:6d08b1476a52

Weblinks app refactor. For Django 1.7.7 upgrade.
author Brian Neal <bgneal@gmail.com>
date Tue, 07 Apr 2015 20:16:06 -0500
parents 988782c6ce6c
children 9d6c2ed2f348
rev   line source
bgneal@690 1 """ receivers.py - Signal receivers for login related events.
bgneal@690 2
bgneal@690 3 We log these events so that fail2ban can perform rate limiting.
bgneal@690 4
bgneal@690 5 """
bgneal@690 6 import logging
bgneal@690 7
bgneal@690 8 from django.contrib.auth.signals import (user_logged_in, user_logged_out,
bgneal@690 9 user_login_failed)
bgneal@690 10
bgneal@690 11
bgneal@690 12 # Get the auth logger that is monitored by fail2ban:
bgneal@690 13 logger = logging.getLogger('auth')
bgneal@690 14
bgneal@690 15
bgneal@690 16 def login_callback(sender, request, user, **kwargs):
bgneal@690 17 """Signal callback function for a user logging in."""
bgneal@690 18 logger.info('User login signal: %s', user.username)
bgneal@690 19
bgneal@690 20
bgneal@690 21 def logout_callback(sender, request, user, **kwargs):
bgneal@690 22 """Signal callback function for a user logging in."""
bgneal@690 23
bgneal@690 24 if user:
bgneal@690 25 logger.info('User logout signal: %s', user.username)
bgneal@690 26
bgneal@690 27 def login_failed_callback(sender, credentials, **kwargs):
bgneal@690 28 """Signal callback for a login failure event."""
bgneal@690 29 logger.error('User login failed signal from %s: %s', sender,
bgneal@690 30 credentials.get('username'))
bgneal@690 31
bgneal@690 32
bgneal@690 33 user_logged_in.connect(login_callback, dispatch_uid='antispam.receivers')
bgneal@690 34 user_logged_out.connect(logout_callback, dispatch_uid='antispam.receivers')
bgneal@690 35 user_login_failed.connect(login_failed_callback,
bgneal@690 36 dispatch_uid='antispam.receivers')