[1] | 1 | from Products.qPloneCaptchas import ProductMessageFactory |
---|
| 2 | from Products.CMFCore.utils import getToolByName |
---|
| 3 | from Products.qPloneCaptchas.utils import decrypt, parseKey, \ |
---|
| 4 | encrypt1, getWord |
---|
| 5 | from DateTime import DateTime |
---|
| 6 | |
---|
| 7 | if state.getStatus()=='failure': |
---|
| 8 | return state |
---|
| 9 | request = context.REQUEST |
---|
| 10 | |
---|
| 11 | test_key = request.get('key', '') |
---|
| 12 | hashkey = request.get('hashkey', '') |
---|
| 13 | decrypted_key = decrypt(context.captcha_key, hashkey) |
---|
| 14 | parsed_key = parseKey(decrypted_key) |
---|
| 15 | |
---|
| 16 | index = parsed_key['key'] |
---|
| 17 | date = parsed_key['date'] |
---|
| 18 | |
---|
| 19 | img = getattr(context, '%s.jpg' % index) |
---|
| 20 | solution = img.title |
---|
| 21 | enc = encrypt1(test_key) |
---|
| 22 | captcha_tool = getToolByName(context, 'portal_captchas') |
---|
| 23 | if (enc != solution) or (captcha_tool.has_key(decrypted_key)) \ |
---|
| 24 | or (DateTime().timeTime() - float(date)>3600): |
---|
| 25 | state.setError('key', ProductMessageFactory("Please re-enter validation code."), 'key_required') |
---|
| 26 | return state.set(status="failure", portal_status_message = ProductMessageFactory("Please re-enter validation code.")) |
---|
| 27 | else: |
---|
| 28 | captcha_tool.addExpiredKey(decrypted_key) |
---|
| 29 | return state.set(status="success") |
---|