Email validation

This commit is contained in:
Katja Süss 2017-06-20 15:16:19 +02:00
parent abe4ef1851
commit 0fd9b02c80
3 changed files with 30 additions and 3 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

@ -1,12 +1,18 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""Interfaces for plone.app.discussion """Interfaces for plone.app.discussion
""" """
from plone import api
from plone.app.discussion import _ from plone.app.discussion import _
from zope import schema from zope import schema
from zope.component.interfaces import IObjectEvent from zope.component.interfaces import IObjectEvent
from zope.interface import Interface from zope.interface import Interface, Invalid
from zope.interface.common.mapping import IIterableMapping from zope.interface.common.mapping import IIterableMapping
def isEmail(value):
reg_tool = api.portal.get_tool(name='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 +156,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'.