# HG changeset patch # User k0s # Date 1266973702 18000 # Node ID b0ef5452a74005e2211cc50467e60624c4eaf857 # Parent c861518b2a443209df0fa583efe68fa90a0ab5b3 beginning of captcha checking diff -r c861518b2a44 -r b0ef5452a740 captchamiddleware/middleware.py --- a/captchamiddleware/middleware.py Tue Feb 23 19:50:23 2010 -0500 +++ b/captchamiddleware/middleware.py Tue Feb 23 20:08:22 2010 -0500 @@ -43,17 +43,29 @@ # characters skimpygimpy doesnt know about forbidden_characters = set(["'"]) - self.words = [ i.strip() for i in f.readlines() + self.words = [ i.strip().lower() for i in f.readlines() if (len(i.strip()) > self.minimum_length) and not forbidden_characters.intersection(i) ] random.shuffle(self.words) + def check_captcha(self, request): + captcha = request.POST.get('captcha', '').lower() + key = request.POST.get('key') + if not key: return False + try: + key = int(key) + except ValueError: + return False + try: + value = self.words[key] + except IndexError: + raise # TODO: better error handling + return value == captcha def __call__(self, environ, start_response): request = Request(environ) if request.method == 'POST' and not request.remote_user: - import pdb; pdb.set_trace() - pass # TODO: check CAPTCHA + return self.app(environ, start_response) return LXMLMiddleware.__call__(self, environ, start_response) @@ -70,7 +82,7 @@ key = random.Random().randint(0, len(self.words)) word = self.words[key] captcha = skimpyAPI.Pre(word).data() - string = '
%s
' % (captcha, key) + string = '
%s
' % (captcha, key) addition = etree.fromstring(string) insertion_point = element.find('.' + self.path) insertion_point.addprevious(addition)