annotate antispam/receivers.py @ 943:cf9918328c64

Haystack tweaks for Django 1.7.7. I had to upgrade to Haystack 2.3.1 to get it to work with Django 1.7.7. I also had to update the Xapian backend. But I ran into problems. On my laptop anyway (Ubuntu 14.0.4), xapian gets mad when search terms are greater than 245 chars (or something) when indexing. So I created a custom field that would simply omit terms greater than 64 chars and used this field everywhere I previously used a CharField. Secondly, the custom search form was broken now. Something changed in the Xapian backend and exact searches stopped working. Fortunately the auto_query (which I was using originally and broke during an upgrade) started working again. So I cut the search form back over to doing an auto_query. I kept the form the same (3 fields) because I didn't want to change the form and I think it's better that way.
author Brian Neal <bgneal@gmail.com>
date Wed, 13 May 2015 20:25:07 -0500
parents 9d6c2ed2f348
children
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@934 27
bgneal@690 28 def login_failed_callback(sender, credentials, **kwargs):
bgneal@690 29 """Signal callback for a login failure event."""
bgneal@690 30 logger.error('User login failed signal from %s: %s', sender,
bgneal@690 31 credentials.get('username'))
bgneal@690 32
bgneal@690 33
bgneal@690 34 user_logged_in.connect(login_callback, dispatch_uid='antispam.receivers')
bgneal@690 35 user_logged_out.connect(logout_callback, dispatch_uid='antispam.receivers')
bgneal@690 36 user_login_failed.connect(login_failed_callback,
bgneal@690 37 dispatch_uid='antispam.receivers')