view antispam/receivers.py @ 821:71db8076dc3d

Bandmap WIP: geocoding integrated with add form. Add form works. Before submitting the form, client side JS makes a geocode request to Google and populates hidden lat/lon fields with the result. Successfully created a model instance on the server side. Still need to update admin dashboard, admin approval, and give out badges for adding bands to the map. Once that is done, then work on displaying the map with filtering.
author Brian Neal <bgneal@gmail.com>
date Tue, 23 Sep 2014 20:40:31 -0500
parents 988782c6ce6c
children 9d6c2ed2f348
line wrap: on
line source
""" receivers.py - Signal receivers for login related events.

We log these events so that fail2ban can perform rate limiting.

"""
import logging

from django.contrib.auth.signals import (user_logged_in, user_logged_out,
        user_login_failed)


# Get the auth logger that is monitored by fail2ban:
logger = logging.getLogger('auth')


def login_callback(sender, request, user, **kwargs):
    """Signal callback function for a user logging in."""
    logger.info('User login signal: %s', user.username)


def logout_callback(sender, request, user, **kwargs):
    """Signal callback function for a user logging in."""

    if user:
        logger.info('User logout signal: %s', user.username)

def login_failed_callback(sender, credentials, **kwargs):
    """Signal callback for a login failure event."""
    logger.error('User login failed signal from %s: %s', sender,
                 credentials.get('username'))


user_logged_in.connect(login_callback, dispatch_uid='antispam.receivers')
user_logged_out.connect(logout_callback, dispatch_uid='antispam.receivers')
user_login_failed.connect(login_failed_callback,
                          dispatch_uid='antispam.receivers')