Merge pull request #124 from ksuess/master

Email validation
This commit is contained in:
Jens W. Klein 2017-06-22 11:32:52 +02:00 committed by GitHub
commit 3465f4e0fd
3 changed files with 33 additions and 2 deletions

View File

@ -10,7 +10,7 @@ Breaking changes:
New features: New features:
- *add item here* - Email validation [ksuess]
Bug fixes: Bug fixes:

View File

@ -2,11 +2,21 @@
"""Interfaces for plone.app.discussion """Interfaces for plone.app.discussion
""" """
from plone.app.discussion import _ from plone.app.discussion import _
from Products.CMFCore.interfaces import ISiteRoot
from Products.CMFCore.utils import getToolByName
from zope import schema from zope import schema
from zope.component import getUtility
from zope.component.interfaces import IObjectEvent from zope.component.interfaces import IObjectEvent
from zope.interface import Interface from zope.interface import Interface
from zope.interface import Invalid
from zope.interface.common.mapping import IIterableMapping from zope.interface.common.mapping import IIterableMapping
def isEmail(value):
portal = getUtility(ISiteRoot)
reg_tool = getToolByName(portal, 'portal_registration')
if not (value and reg_tool.isValidEmail(value)):
raise Invalid(_("Invalid email address."))
return True
class IConversation(IIterableMapping): class IConversation(IIterableMapping):
"""A conversation about a content object. """A conversation about a content object.
@ -150,7 +160,7 @@ class IComment(Interface):
# for anonymous comments only, set to None for logged in comments # for anonymous comments only, set to None for logged in comments
author_name = schema.TextLine(title=_(u'Name'), required=False) author_name = schema.TextLine(title=_(u'Name'), required=False)
author_email = schema.TextLine(title=_(u'Email'), required=False) author_email = schema.TextLine(title=_(u'Email'), required=False, constraint=isEmail)
title = schema.TextLine(title=_(u'label_subject', title = schema.TextLine(title=_(u'label_subject',
default=u'Subject')) default=u'Subject'))

View File

@ -514,6 +514,27 @@ Try again.
>>> 'Your comment awaits moderator approval' in unprivileged_browser.contents >>> 'Your comment awaits moderator approval' in unprivileged_browser.contents
True True
Email is being validated.
>>> unprivileged_browser.getControl(name='form.widgets.text').value = "This is an anonymous comment with email"
>>> unprivileged_browser.getControl(name='form.widgets.author_email').value = "abc"
>>> unprivileged_browser.getControl(name='form.buttons.comment').click()
>>> 'Invalid email address.' in unprivileged_browser.contents
True
>>> 'Your comment awaits moderator approval' in unprivileged_browser.contents
False
Check again with valid email.
>>> unprivileged_browser.getControl(name='form.widgets.text').value = "This is an anonymous comment with email"
>>> unprivileged_browser.getControl(name='form.widgets.author_email').value = "email@example.org"
>>> unprivileged_browser.getControl(name='form.buttons.comment').click()
>>> 'Invalid email address.' in unprivileged_browser.contents
False
>>> 'Your comment awaits moderator approval' in unprivileged_browser.contents
True
Posting as member should still work. Especially it should not Posting as member should still work. Especially it should not
complain about missing input for an invisible author_email field. complain about missing input for an invisible author_email field.
Login as user 'jim'. Login as user 'jim'.