source: products/qPloneCaptchas/tags/0.9/skins/plone_captchas/captcha_validator.vpy @ 458

Last change on this file since 458 was 1, checked in by myroslav, 19 years ago

Building directory structure

  • Property svn:eol-style set to native
File size: 1.0 KB
Line 
1from Products.qPloneCaptchas.config import havePIL
2from Products.qPloneCaptchas.utils import decrypt, parseKey, \
3     encrypt1, getWord, addExpiredKey
4from DateTime import DateTime
5
6if state.getStatus()=='failure':
7    return  state
8request = context.REQUEST
9
10test_key = request.get('key', '')
11hashkey = request.get('hashkey', '')
12decrypted_key = decrypt(context.captcha_key, hashkey)
13parsed_key = parseKey(decrypted_key)
14 
15index = parsed_key['key']
16date = parsed_key['date']
17
18if havePIL:
19    enc = test_key
20    solution = getWord(int(index))
21else:
22    img = getattr(context, '%s.jpg' % index)
23    solution = img.title
24    enc = encrypt1(test_key)
25
26if (enc != solution) or (context.portal_captchas.has_key(decrypted_key)) \
27   or (DateTime().timeTime() - float(date)>3600):
28   state.setError('key', 'Please re-enter validation code.', 'key_required')
29   return state.set(status="failure", portal_status_message = "Please re-enter validation code.")
30else:
31    addExpiredKey(context, decrypted_key)
32    return state.set(status="success")
Note: See TracBrowser for help on using the repository browser.