comparison antispam/decorators.py @ 692:4a49d4ac319f

For #51, remove the ajax popup login window.
author Brian Neal <bgneal@gmail.com>
date Sun, 01 Sep 2013 15:58:45 -0500
parents 988782c6ce6c
children
comparison
equal deleted inserted replaced
691:81e0be69b3a5 692:4a49d4ac319f
1 """ 1 """
2 This module contains decorators for the antispam application. 2 This module contains decorators for the antispam application.
3 3
4 """ 4 """
5 import json
6 from functools import wraps 5 from functools import wraps
7 import logging 6 import logging
8 7
9 8
10 def log_auth_failures(auth_type): 9 def log_auth_failures(auth_type):
17 16
18 response = fn(request, *args, **kwargs) 17 response = fn(request, *args, **kwargs)
19 18
20 if request.method == 'POST': 19 if request.method == 'POST':
21 20
22 # Figure out if the view succeeded; if it is a non-ajax view, 21 # Figure out if the view succeeded; success means a redirect is
23 # then success means a redirect is about to occur. If it is 22 # about to occur.
24 # an ajax view, we have to decode the json response. 23 success = (response and response.has_header('location') and
25 success = False 24 response.status_code == 302)
26 if not request.is_ajax():
27 success = (response and response.has_header('location') and
28 response.status_code == 302)
29 elif response:
30 json_resp = json.loads(response.content)
31 success = json_resp['success']
32 25
33 if not success: 26 if not success:
34 username = request.POST.get('username') 27 username = request.POST.get('username')
35 username = username if username else '(None)' 28 username = username if username else '(None)'
36 logger.error("%s failure from [%s] for %s", 29 logger.error("%s failure from [%s] for %s",