comparison antispam/receivers.py @ 690:988782c6ce6c

For #48, rework blocking code to use fail2ban.
author Brian Neal <bgneal@gmail.com>
date Sun, 01 Sep 2013 00:15:42 -0500
parents
children 9d6c2ed2f348
comparison
equal deleted inserted replaced
689:a8dc08cc5db4 690:988782c6ce6c
1 """ receivers.py - Signal receivers for login related events.
2
3 We log these events so that fail2ban can perform rate limiting.
4
5 """
6 import logging
7
8 from django.contrib.auth.signals import (user_logged_in, user_logged_out,
9 user_login_failed)
10
11
12 # Get the auth logger that is monitored by fail2ban:
13 logger = logging.getLogger('auth')
14
15
16 def login_callback(sender, request, user, **kwargs):
17 """Signal callback function for a user logging in."""
18 logger.info('User login signal: %s', user.username)
19
20
21 def logout_callback(sender, request, user, **kwargs):
22 """Signal callback function for a user logging in."""
23
24 if user:
25 logger.info('User logout signal: %s', user.username)
26
27 def login_failed_callback(sender, credentials, **kwargs):
28 """Signal callback for a login failure event."""
29 logger.error('User login failed signal from %s: %s', sender,
30 credentials.get('username'))
31
32
33 user_logged_in.connect(login_callback, dispatch_uid='antispam.receivers')
34 user_logged_out.connect(logout_callback, dispatch_uid='antispam.receivers')
35 user_login_failed.connect(login_failed_callback,
36 dispatch_uid='antispam.receivers')