source: products/qPloneCaptchaField/trunk/validators/captcha_validator.py @ 3665

Last change on this file since 3665 was 1, checked in by myroslav, 15 years ago

Building directory structure

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