Changeset 3121 in products for quintagroup.formlib.captcha/trunk/quintagroup/formlib/captcha/widget.py
- Timestamp:
- Apr 15, 2011 1:00:00 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.formlib.captcha/trunk/quintagroup/formlib/captcha/widget.py
r3098 r3121 23 23 logger = logging.getLogger('quintagroup.formlib.captcha') 24 24 25 25 26 class CaptchaWidget(ASCIIWidget): 26 27 … … 42 43 43 44 site = self.get_site() 44 portal_url = getToolByName(site 45 portal_url = getToolByName(site, 'portal_url')() 45 46 key = site.getCaptcha() 46 47 … … 52 53 return u"""<input type="hidden" value="%s" name="%shashkey" /> 53 54 %s 54 <img src="%s/getCaptchaImage/%s" alt="Enter the word"/>""" % (key, 55 prefix, 56 renderElement(self.tag, **kwargs), 57 portal_url, 58 key) 59 55 <img src="%s/getCaptchaImage/%s" 56 alt="Enter the word"/>""" % (key, 57 prefix, 58 renderElement(self.tag, 59 **kwargs), 60 portal_url, 61 key) 62 60 63 def _toFieldValue(self, input): 61 64 # Verify the user input against the captcha … … 64 67 site = self.get_site() 65 68 captcha_type = site.getCaptchaType() 66 69 67 70 # validate captcha input 68 71 if input and captcha_type in ['static', 'dynamic']: … … 72 75 else: 73 76 prefix = '' 74 77 75 78 hashkey = self.request.get('%shashkey' % prefix, '') 76 79 decrypted_key = decrypt(site.captcha_key, hashkey) 77 80 parsed_key = parseKey(decrypted_key) 78 81 79 82 index = parsed_key['key'] 80 83 date = parsed_key['date'] 81 84 82 85 if captcha_type == 'static': 83 86 img = getattr(site, '%s.jpg' % index) … … 87 90 enc = input 88 91 solution = getWord(int(index)) 89 92 90 93 captcha_tool = getToolByName(site, 'portal_captchas') 91 if (enc != solution) or (captcha_tool.has_key(decrypted_key)) or (DateTime().timeTime() - float(date) > 3600): 94 if (enc != solution) or (decrypted_key in captcha_tool) or \ 95 (DateTime().timeTime() - float(date) > 3600): 92 96 raise ConversionError(_(u'Please re-enter validation code.')) 93 97 else: 94 98 captcha_tool.addExpiredKey(decrypted_key) 95 99 96 100 return super(CaptchaWidget, self)._toFieldValue(input)
Note: See TracChangeset
for help on using the changeset viewer.