show captcha validation only for anonymous users.

svn path=/plone.app.discussion/trunk/; revision=28902
This commit is contained in:
Timo Stollenwerk 2009-08-15 11:35:54 +00:00
parent 2567483281
commit bbf7cb5685
2 changed files with 8 additions and 2 deletions

View File

@ -1,5 +1,7 @@
from persistent import Persistent
from Products.CMFCore.utils import getToolByName
from z3c.form import validator
from z3c.form.field import Fields
@ -59,9 +61,11 @@ if HAS_CAPTCHA or HAS_RECAPTCHA:
registry = queryUtility(IRegistry)
settings = registry.forInterface(IDiscussionSettings)
self.captcha = settings.captcha
portal_membership = getToolByName(self.context, 'portal_membership')
self.isAnon = portal_membership.isAnonymousUser()
def update(self):
if self.captcha != 'disabled':
if self.captcha != 'disabled' and self.isAnon:
# Add captcha field if captcha is enabled in the registry
self.add(ICaptcha, prefix="")
if HAS_CAPTCHA and self.captcha == 'captcha':

View File

@ -79,9 +79,11 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
def handleComment(self, action):
data, errors = self.extractData()
# Captcha check (only when captcha is enabled and user is anonymous)
registry = queryUtility(IRegistry)
settings = registry.forInterface(IDiscussionSettings)
if settings.captcha != 'disabled':
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