Last change
on this file since 3152 was
1,
checked in by myroslav, 19 years ago
|
Building directory structure
|
-
Property svn:eol-style set to
native
|
File size:
823 bytes
|
Line | |
---|
1 | from Products.CMFCore.utils import getToolByName |
---|
2 | from Products.validation import validation, interfaces |
---|
3 | |
---|
4 | from Products.CMFPlone.utils import safe_hasattr |
---|
5 | |
---|
6 | class 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 | |
---|
27 | validation.register(CaptchaValidator('isCaptchaCorrect')) |
---|
Note: See
TracBrowser
for help on using the repository browser.