source: products/quintagroup.pfg.captcha/trunk/quintagroup/pfg/captcha/validator.py @ 2295

Last change on this file since 2295 was 2295, checked in by chervol, 13 years ago

fixed interface binding

  • Property svn:eol-style set to native
File size: 895 bytes
Line 
1from Products.CMFCore.utils import getToolByName
2from Products.validation import validation
3from Products.validation.interfaces.IValidator import IValidator
4from zope.interface import implements
5
6from Products.CMFPlone.utils import safe_hasattr
7
8class CaptchaValidator:
9
10    implements(IValidator)
11
12    name = 'CaptchaValidator'
13
14    def __init__(self, name, title='', description=''):
15        self.name = name
16        self.title = title or name
17        self.description = description
18
19    def __call__(self, value, *args, **kwargs):
20
21        form  = kwargs.get('instance')
22        portal = getToolByName(form, 'portal_url').getPortalObject()
23        result = portal.captcha_validator()
24        if result.status == 'failure':
25            return ("%(problem)s" % {'problem' : result.errors['key'][0]})
26        else:
27            return 1
28
29validation.register(CaptchaValidator('isCaptchaCorrect'))
Note: See TracBrowser for help on using the repository browser.