bgneal@472: """ bgneal@472: This module contains decorators for the antispam application. bgneal@472: bgneal@472: """ bgneal@472: from functools import wraps bgneal@690: import logging bgneal@472: bgneal@472: bgneal@690: def log_auth_failures(auth_type): bgneal@472: bgneal@472: def decorator(fn): bgneal@690: logger = logging.getLogger('auth') bgneal@472: bgneal@472: @wraps(fn) bgneal@472: def wrapped(request, *args, **kwargs): bgneal@472: bgneal@472: response = fn(request, *args, **kwargs) bgneal@472: bgneal@472: if request.method == 'POST': bgneal@505: bgneal@692: # Figure out if the view succeeded; success means a redirect is bgneal@692: # about to occur. bgneal@692: success = (response and response.has_header('location') and bgneal@692: response.status_code == 302) bgneal@505: bgneal@505: if not success: bgneal@690: username = request.POST.get('username') bgneal@690: username = username if username else '(None)' bgneal@690: logger.error("%s failure from [%s] for %s", bgneal@690: auth_type, bgneal@690: request.META.get('REMOTE_ADDR', '?'), bgneal@690: username) bgneal@479: bgneal@472: return response bgneal@472: bgneal@472: return wrapped bgneal@472: return decorator