1 | from Products.qPloneCaptchas.config import havePIL |
---|
2 | from Products.qPloneCaptchas.utils import decrypt, parseKey, \ |
---|
3 | encrypt1, getWord, addExpiredKey |
---|
4 | from DateTime import DateTime |
---|
5 | |
---|
6 | if state.getStatus()=='failure': |
---|
7 | return state |
---|
8 | request = context.REQUEST |
---|
9 | |
---|
10 | test_key = request.get('key', '') |
---|
11 | hashkey = request.get('hashkey', '') |
---|
12 | decrypted_key = decrypt(context.captcha_key, hashkey) |
---|
13 | parsed_key = parseKey(decrypted_key) |
---|
14 | |
---|
15 | index = parsed_key['key'] |
---|
16 | date = parsed_key['date'] |
---|
17 | |
---|
18 | if havePIL: |
---|
19 | enc = test_key |
---|
20 | solution = getWord(int(index)) |
---|
21 | else: |
---|
22 | img = getattr(context, '%s.jpg' % index) |
---|
23 | solution = img.title |
---|
24 | enc = encrypt1(test_key) |
---|
25 | |
---|
26 | if (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.") |
---|
30 | else: |
---|
31 | addExpiredKey(context, decrypted_key) |
---|
32 | return state.set(status="success") |
---|