From dbff6b4f671378601efd1c55695bfc03a7298084 Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Sat, 15 Aug 2009 16:36:35 +0000 Subject: [PATCH] add captcha check for reply-to-comment form. svn path=/plone.app.discussion/trunk/; revision=28922 --- plone/app/discussion/browser/comments.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/plone/app/discussion/browser/comments.py b/plone/app/discussion/browser/comments.py index 3370154..589aa7f 100644 --- a/plone/app/discussion/browser/comments.py +++ b/plone/app/discussion/browser/comments.py @@ -150,9 +150,22 @@ class CommentForm(extensible.ExtensibleForm, form.Form): @button.buttonAndHandler(_(u"Reply")) def handleReply(self, action): - 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'): title = data['title']