def __call__(self): """Confirm the code or render the form.""" # make sure we have the form marker interface when testing z2.switch_on(self) if self.confirm_code: # confirm/delete nonce nonce_store = getUtility(INonceManager) try: email = nonce_store.retrieve(self.confirm_code) except KeyError: self.status = _(u'Sorry, your confirmation code is invalid or has expired.') else: # set up session session = ISession(self.request) session['collective.confirm_email.confirmed'] = True session['collective.confirm_email.email'] = email session.save() # redirect back to target (by removing last 2 parts of path) raise Redirect(self.request['URL2']) # render form return super(EmailConfirmationForm, self).__call__()
def handleSend(self, action): data, errors = self.widgets.extract() if errors: self.status = _('There were errors.') return nonce_store = getUtility(INonceManager) nonce = nonce_store.store(data['email']) url = '%s/%s' % (self.orig_url or self.request['URL'], nonce) msg = "Please click this link to continue.\n %s" % url mto = data['email'] mfrom = '*****@*****.**' if HAS_SITE_ROOT: site = queryUtility(ISiteRoot) if site is not None: mfrom = site.email_from_address subject = 'E-mail confirmation' mailhost = getUtility(IMailHost) mailhost.send(msg, mto, mfrom, subject) self.status = _(u'Confirmation was sent.')