Changeset 2799 in products
- Timestamp:
- Sep 9, 2010 5:37:06 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.formlib.captcha/trunk/quintagroup/formlib/captcha/widget.py
r2210 r2799 1 1 from DateTime import DateTime 2 2 3 from zope.component import getMultiAdapter 3 try: 4 from zope.site.hooks import getSite 5 except ImportError: 6 from zope.app.component.hooks import getSite 4 7 from zope.app.form.browser import ASCIIWidget 5 8 from zope.app.form.interfaces import ConversionError … … 10 13 11 14 from Products.CMFCore.utils import getToolByName 15 from Products.CMFCore.interfaces import ISiteRoot 12 16 13 17 from quintagroup.captcha.core.utils import decrypt, parseKey, encrypt1, getWord … … 15 19 _ = MessageFactory('quintagroup.formlib.captcha') 16 20 21 import logging 22 23 logger = logging.getLogger('quintagroup.formlib.captcha') 17 24 18 25 class CaptchaWidget(ASCIIWidget): 26 27 def get_site(self): 28 # get from plone.app.form.widgets.wysiwygwdget 29 site = getSite() 30 while site is not None and not ISiteRoot.providedBy(site): 31 site = aq_parent(site) 32 return site 33 19 34 def __call__(self): 20 context = self.context.context21 22 35 kwargs = {'type': self.type, 23 36 'name': self.name, … … 28 41 'extra': self.extra} 29 42 30 portal_url = getToolByName(context, 'portal_url')() 31 key = context.getCaptcha() 43 site = self.get_site() 44 portal_url = getToolByName(site , 'portal_url')() 45 key = site.getCaptcha() 32 46 33 47 if self._prefix: … … 46 60 def _toFieldValue(self, input): 47 61 # Verify the user input against the captcha 48 context = self.context.context 49 request = context.REQUEST 50 62 51 63 # get captcha type (static or dynamic) 52 captcha_type = context.getCaptchaType() 64 site = self.get_site() 65 captcha_type = site.getCaptchaType() 53 66 54 67 # validate captcha input … … 60 73 prefix = '' 61 74 62 hashkey = request.get('%shashkey' % prefix, '')63 decrypted_key = decrypt( context.captcha_key, hashkey)75 hashkey = self.request.get('%shashkey' % prefix, '') 76 decrypted_key = decrypt(site.captcha_key, hashkey) 64 77 parsed_key = parseKey(decrypted_key) 65 78 … … 68 81 69 82 if captcha_type == 'static': 70 img = getattr( context, '%s.jpg' % index)83 img = getattr(site, '%s.jpg' % index) 71 84 solution = img.title 72 85 enc = encrypt1(input) … … 75 88 solution = getWord(int(index)) 76 89 77 captcha_tool = getToolByName( context, 'portal_captchas')90 captcha_tool = getToolByName(site, 'portal_captchas') 78 91 if (enc != solution) or (captcha_tool.has_key(decrypted_key)) or (DateTime().timeTime() - float(date) > 3600): 79 92 raise ConversionError(_(u'Please re-enter validation code.'))
Note: See TracChangeset
for help on using the changeset viewer.