Skip to content
Browse files

Add change_email view

  • Loading branch information...
1 parent efbe1ae commit c230dd8a2b265ff8853f1d1919aafbd4d3beb6d6 @csenger csenger committed
View
59 Products/EasyNewsletter/browser/change_email.pt
@@ -0,0 +1,59 @@
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
+ lang="en"
+ metal:use-macro="here/main_template/macros/master"
+ i18n:domain="EasyNewsletter">
+<body>
+
+<div metal:fill-slot="main">
+
+ <br/>
+ <form method="post"
+ id="change_email_form"
+ tal:attributes="action string:${context/absolute_url}/change_email">
+
+ <input type="hidden"
+ name="subscriber"
+ tal:attributes="value python:context.REQUEST.get('subscriber', '')"
+ />
+
+ <br/><br/>
+
+ <label for="new"
+ i18n:translate="EasyNewsletter_label_newEmail">
+ New email address
+ </label>
+
+ <input type="text"
+ name="new"
+ size="40"
+ tal:attributes="value python:context.REQUEST.get('new', '')" />
+
+ <br/><br/>
+
+
+ <label for="new_confirm"
+ i18n:translate="EasyNewsletter_label_confirmNnewEmail">
+ Confirm new email address
+ </label>
+
+ <input type="text"
+ name="confirm_new"
+ size="40"
+ tal:attributes="value python:context.REQUEST.get('new', '')" />
+
+ <br/><br/>
+
+ <input id="form_send"
+ class="send"
+ type="submit"
+ name="send"
+ value="change_email" />
+
+ </form>
+
+
+
+</div>
+
+</body>
+</html>
View
7 Products/EasyNewsletter/browser/configure.zcml
@@ -109,4 +109,11 @@
attribute="confirm_newsletter"
permission="zope2.Public" />
+ <browser:page
+ name="change_email"
+ for="..interfaces.IEasyNewsletter"
+ class=".newsletter.NewsletterView"
+ attribute="change_email"
+ permission="zope2.Public" />
+
</configure>
View
41 Products/EasyNewsletter/browser/newsletter.py
@@ -1,6 +1,7 @@
from AccessControl.SecurityManagement import newSecurityManager
from Products.CMFCore.utils import getToolByName
from Products.Five.browser import BrowserView
+from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from Products.EasyNewsletter import EasyNewsletterMessageFactory as _
@@ -9,6 +10,8 @@ class NewsletterView(BrowserView):
"""
"""
+ confirm_email_template = ViewPageTemplateFile('change_email.pt')
+
def unsubscribe(self):
"""
"""
@@ -63,3 +66,41 @@ def confirm_newsletter(self):
putils.addPortalMessage(_("You have confirmed the email address."))
change_email_url = self.context.er_change_email_url(uid)
return self.request.response.redirect(change_email_url)
+
+ def change_email(self):
+ putils = getToolByName(self.context, "plone_utils")
+ catalog = getToolByName(self.context, "reference_catalog")
+ registration_tool = getToolByName(self, 'portal_registration')
+
+ uid = self.request.get("subscriber")
+ subscriber = catalog.lookupObject(uid)
+ newsletter_url = self.context.absolute_url()
+ if subscriber is None:
+ putils.addPortalMessage(_("Subscriber not found"), "error")
+ return self.request.response.redirect(newsletter_url)
+
+ if self.request.method == 'POST':
+ new_email = self.request.get("new", '').strip()
+ new_email_confirm = self.request.get("confirm_new",
+ '').strip()
+ errors = False
+ if not registration_tool.isValidEmail(new_email):
+ putils.addPortalMessage(
+ _('Please specify a valid new email address.'), 'error')
+ errors = True
+ if new_email != new_email_confirm:
+ putils.addPortalMessage(
+ _('The new email addresses you gave do not match.'),
+ 'error')
+ errors = True
+ if errors:
+ return self.confirm_email_template()
+
+ subscriber.email = new_email
+ putils.addPortalMessage(
+ _('The email address for your subscription was '
+ 'changed to: ${email}',
+ mapping={'email': new_email}), 'info')
+ return self.request.response.redirect(newsletter_url)
+
+ return self.confirm_email_template()

0 comments on commit c230dd8

Please sign in to comment.
Something went wrong with that request. Please try again.