add captcha check for reply-to-comment form.

svn path=/plone.app.discussion/trunk/; revision=28922
This commit is contained in:
Timo Stollenwerk 2009-08-15 16:36:35 +00:00
parent bbf7cb5685
commit dbff6b4f67

View File

@ -150,9 +150,22 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
@button.buttonAndHandler(_(u"Reply")) @button.buttonAndHandler(_(u"Reply"))
def handleReply(self, action): def handleReply(self, action):
data, errors = self.extractData() data, errors = self.extractData()
# Captcha check (only when captcha is enabled and user is anonymous)
registry = queryUtility(IRegistry)
settings = registry.forInterface(IDiscussionSettings)
portal_membership = getToolByName(self.context, 'portal_membership')
if settings.captcha != 'disabled' and portal_membership.isAnonymousUser():
# Check captcha only if it is not disabled
if data.has_key('captcha'):
# Check captcha only if there is a value, otherwise
# the default "required" validator is sufficient.
captcha = CaptchaValidator(self.context, self.request, None, ICaptcha['captcha'], None)
captcha.validate(data['captcha'])
else:
return
if data.has_key('title') and data.has_key('text') and data.has_key('in_reply_to'): if data.has_key('title') and data.has_key('text') and data.has_key('in_reply_to'):
title = data['title'] title = data['title']