do not make a captcha check when captcha is disabled; this fixes the non-captcha comment form.

svn path=/plone.app.discussion/trunk/; revision=28790
This commit is contained in:
Timo Stollenwerk 2009-08-13 19:21:52 +00:00
parent ce30a1b594
commit 2a1ae7dc62

View File

@ -32,7 +32,9 @@ from plone.registry.interfaces import IRegistry
from plone.app.layout.viewlets.common import ViewletBase from plone.app.layout.viewlets.common import ViewletBase
from plone.app.discussion.comment import Comment, CommentFactory from plone.app.discussion.comment import Comment, CommentFactory
from plone.app.discussion.interfaces import IConversation, IComment, IReplies, IDiscussionSettings from plone.app.discussion.interfaces import IConversation, IComment, IReplies, IDiscussionSettings, ICaptcha
from plone.formwidget.captcha.validator import CaptchaValidator
from plone.z3cform import layout, z2 from plone.z3cform import layout, z2
from plone.z3cform.fieldsets import extensible from plone.z3cform.fieldsets import extensible
@ -77,16 +79,17 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
def handleComment(self, action): def handleComment(self, action):
data, errors = self.extractData() data, errors = self.extractData()
if data.has_key('captcha'): registry = queryUtility(IRegistry)
from plone.formwidget.captcha.validator import CaptchaValidator settings = registry.forInterface(IDiscussionSettings)
from plone.app.discussion.interfaces import ICaptcha if settings.captcha != 'disabled':
# Verify the user input against the captcha # Check captcha only if it is not disabled
captcha = CaptchaValidator(self.context, self.request, None, ICaptcha['captcha'], None) if data.has_key('captcha'):
if data.has_key('subject') and captcha.validate(data['captcha']): # Check captcha only if there is a value, otherwise
# if captcha validation passes, print the subject # the default "required" validator is sufficient.
print data['subject'] captcha = CaptchaValidator(self.context, self.request, None, ICaptcha['captcha'], None)
else: captcha.validate(data['captcha'])
return else:
return
if data.has_key('title') and data.has_key('text'): if data.has_key('title') and data.has_key('text'):