captcha registry entry and vocabulary added.
svn path=/plone.app.discussion/trunk/; revision=28679
This commit is contained in:
parent
572b743d04
commit
7f7c4b1345
@ -7,21 +7,23 @@ from zope import interface, schema
|
||||
from zope.annotation import factory
|
||||
from zope.annotation.attribute import AttributeAnnotations
|
||||
|
||||
from zope.component import adapts, provideAdapter
|
||||
|
||||
from zope.component import adapts, provideAdapter, queryUtility
|
||||
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
|
||||
|
||||
from zope.interface import Interface, implements
|
||||
|
||||
from plone.registry.interfaces import IRegistry
|
||||
|
||||
from plone.z3cform.fieldsets import extensible
|
||||
from plone.z3cform.fieldsets.interfaces import IFormExtender
|
||||
|
||||
from plone.app.discussion.comment import Comment
|
||||
from plone.app.discussion.browser.comments import CommentForm
|
||||
from plone.app.discussion.comment import Comment
|
||||
from plone.app.discussion.interfaces import IDiscussionSettings
|
||||
|
||||
class ICaptcha(Interface):
|
||||
captcha = schema.TextLine(title=u"Type the word 'human' in all capital letters.",
|
||||
required=False)
|
||||
captcha = schema.TextLine(title=u"Captcha",
|
||||
required=True)
|
||||
|
||||
class Captcha(Persistent):
|
||||
interface.implements(ICaptcha)
|
||||
@ -40,6 +42,15 @@ class CaptchaExtender(extensible.FormExtender):
|
||||
self.request = request
|
||||
self.form = form
|
||||
|
||||
registry = queryUtility(IRegistry)
|
||||
settings = registry.forInterface(IDiscussionSettings)
|
||||
self.captcha = settings.captcha
|
||||
|
||||
def update(self):
|
||||
if self.captcha != 'disabled':
|
||||
# Add all fields from the captcha interface
|
||||
self.add(ICaptcha, prefix="extra")
|
||||
self.add(ICaptcha, prefix="")
|
||||
if self.captcha == 'captcha':
|
||||
self.form.fields['captcha'].widgetFactory = CaptchaFieldWidget
|
||||
elif self.captcha == 'recaptcha':
|
||||
self.form.fields['captcha'].widgetFactory = ReCaptchaFieldWidget
|
@ -71,6 +71,10 @@
|
||||
handler=".tool.unindex_object"
|
||||
/>
|
||||
|
||||
<!-- Captcha Vocabulary -->
|
||||
<utility component=".vocabularies.captcha_vocabulary"
|
||||
name="plone.app.discussion.vocabularies.CaptchaVocabulary" />
|
||||
|
||||
<!-- Conversation indexes -->
|
||||
<adapter name="total_comments" factory=".catalog.total_comments" />
|
||||
<adapter name="last_comment_date" factory=".catalog.last_comment_date" />
|
||||
|
@ -25,6 +25,14 @@ class IDiscussionSettings(Interface):
|
||||
description=_(u"Use this setting to enable or disable posting comments as anonymous visitor."),
|
||||
default=False)
|
||||
|
||||
captcha = schema.Choice(title=_(u"Captcha"),
|
||||
description=_(u"""Use this setting to enable or disable captcha validation for comments.
|
||||
If no captcha options are available, install captcha solutions like
|
||||
plone.formwidget.captcha or plone.formwidget.recaptcha."""),
|
||||
required=True,
|
||||
default='disabled',
|
||||
vocabulary='plone.app.discussion.vocabularies.CaptchaVocabulary',)
|
||||
|
||||
show_commenter_image = schema.Bool(title=_(u"Show commenter image"),
|
||||
description=_(u"Use this setting to enable or disable showing the commenter's image next to his/her comments."),
|
||||
default=True)
|
||||
|
@ -1,5 +1,7 @@
|
||||
import unittest
|
||||
|
||||
from zope.component import getMultiAdapter
|
||||
|
||||
from plone.registry import Registry
|
||||
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
@ -31,6 +33,13 @@ class RegistryTest(PloneTestCase):
|
||||
self.failUnless('globally_enabled' in IDiscussionSettings)
|
||||
self.assertEquals(self.registry['plone.app.discussion.interfaces.IDiscussionSettings.globally_enabled'], True)
|
||||
|
||||
def test_captcha(self):
|
||||
# Check globally_enabled record
|
||||
globally_enabled_record = self.registry.records['plone.app.discussion.interfaces.IDiscussionSettings.captcha']
|
||||
|
||||
self.failUnless('captcha' in IDiscussionSettings)
|
||||
self.assertEquals(self.registry['plone.app.discussion.interfaces.IDiscussionSettings.captcha'], 'disabled')
|
||||
|
||||
def test_anonymous_comments(self):
|
||||
# Check anonymous_comments record
|
||||
anonymous_comments_record = self.registry.records['plone.app.discussion.interfaces.IDiscussionSettings.anonymous_comments']
|
||||
|
48
plone/app/discussion/vocabularies.py
Normal file
48
plone/app/discussion/vocabularies.py
Normal file
@ -0,0 +1,48 @@
|
||||
from zope import interface
|
||||
from zope import component
|
||||
import zope.schema.interfaces
|
||||
import zope.schema.vocabulary
|
||||
|
||||
# XXX: REPLACE THIS!!!
|
||||
HAS_CAPTCHA=False
|
||||
HAS_RECAPTCHA=False
|
||||
|
||||
try:
|
||||
from plone.formwidget.captcha.widget import CaptchaFieldWidget
|
||||
HAS_CAPTCHA = True
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
try:
|
||||
from plone.formwidget.captcha.widget import ReCaptchaFieldWidget
|
||||
HAS_RECAPTCHA = True
|
||||
except ImportError:
|
||||
pass
|
||||
# XXX: REPLACE THIS!!!
|
||||
|
||||
def captcha_vocabulary(context):
|
||||
"""Vocabulary with all available captcha implementations.
|
||||
"""
|
||||
terms = []
|
||||
terms.append(
|
||||
zope.schema.vocabulary.SimpleTerm(
|
||||
value='disabled',
|
||||
token='disabled',
|
||||
title='Disabled'))
|
||||
|
||||
if HAS_CAPTCHA:
|
||||
terms.append(
|
||||
zope.schema.vocabulary.SimpleTerm(
|
||||
value='captcha',
|
||||
token='captcha',
|
||||
title='Captcha'))
|
||||
if HAS_RECAPTCHA:
|
||||
terms.append(
|
||||
zope.schema.vocabulary.SimpleTerm(
|
||||
value='recaptcha',
|
||||
token='recaptcha',
|
||||
title='ReCaptcha'))
|
||||
return zope.schema.vocabulary.SimpleVocabulary(terms)
|
||||
|
||||
interface.alsoProvides(captcha_vocabulary,
|
||||
zope.schema.interfaces.IVocabularyFactory)
|
Loading…
Reference in New Issue
Block a user