def initiateRequest(self, account, login): if account.change_request is None: account.change_request = AccountChangeRequest() account.change_request.id = randomString() account.change_request.expires = datetime.datetime.now() + \ datetime.timedelta(days=7) account.change_request.value = login client_url = self.request.client.absolute_url() confirm_url = "%s/confirm-change?%s" % (client_url, urllib.urlencode({"key": account.change_request.id})) site = getUtility(ISiteRoot) mailhost = getToolByName(self.context, "MailHost") body = self.email_template(account=account, new_login=login, client_url=client_url, confirm_url=confirm_url) subject = translate(_(u"Confirm OiRA email address change"), context=self.request) mail = CreateEmailTo(site.email_from_name, site.email_from_address, login, subject, body) flash = IStatusMessage(self.request).addStatusMessage try: mailhost.send(mail, login, site.email_from_address, immediate=True) log.info("Sent email confirmation to %s", account.email) except MailHostError, e: log.error("MailHost error sending email confirmation to %s: %s", account.email, e) flash(_(u"An error occured while sending the confirmation email."), "error") return False
def initiateRequest(self, account, login): if account.change_request is None: account.change_request = AccountChangeRequest() account.change_request.id = randomString() account.change_request.expires = datetime.datetime.now() + \ datetime.timedelta(days=7) account.change_request.value = login client_url = self.request.client.absolute_url() confirm_url = "%s/confirm-change?%s" % ( client_url, urllib.urlencode({"key": account.change_request.id})) site = getUtility(ISiteRoot) mailhost = getToolByName(self.context, "MailHost") body = self.email_template(account=account, new_login=login, client_url=client_url, confirm_url=confirm_url) subject = translate(_(u"Confirm OiRA email address change"), context=self.request) mail = CreateEmailTo(site.email_from_name, site.email_from_address, login, subject, body) flash = IStatusMessage(self.request).addStatusMessage try: mailhost.send(mail, login, site.email_from_address, immediate=True) log.info("Sent email confirmation to %s", account.email) except MailHostError as e: log.error("MailHost error sending email confirmation to %s: %s", account.email, e) flash(_(u"An error occured while sending the confirmation email."), "error") return False except smtplib.SMTPException as e: log.error("smtplib error sending password reminder to %s: %s", account.email, e) flash(_(u"An error occured while sending the confirmation email."), "error") return False except socket.error as e: log.error("Socket error sending password reminder to %s: %s", account.email, e[1]) flash(_(u"An error occured while sending the confirmation email."), "error") return False return True
def testLength(self): self.assertEquals(len(utils.randomString(5)), 5)
def testOutputChanges(self): self.assertNotEquals(utils.randomString(), utils.randomString())
def initiateRequest(self, account, login): flash = IStatusMessage(self.request).addStatusMessage # Make it work when acl_users is in Memcached: We need to fetch the # account again, to prevent DetachedInstanceError account_query = Session.query(Account).filter(Account.id == account.id) if not account_query.count(): log.error("Account could not be fetched") flash(_("An error occured while sending the confirmation email."), "error") return False account = account_query.one() if account.change_request is None: account.change_request = AccountChangeRequest() account.change_request.id = randomString() account.change_request.expires = datetime.datetime.now( ) + datetime.timedelta(days=7) account.change_request.value = login client_url = self.request.client.absolute_url() confirm_url = "%s/confirm-change?%s" % ( client_url, urlencode({"key": account.change_request.id}), ) mailhost = getToolByName(self.context, "MailHost") body = self.email_template( account=account, new_login=login, client_url=client_url, confirm_url=confirm_url, ) subject = translate(_("Confirm OiRA email address change"), context=self.request) mail = CreateEmailTo(self.email_from_name, self.email_from_address, login, subject, body) try: mailhost.send(mail, login, self.email_from_address, immediate=True) log.info("Sent email confirmation to %s", account.email) except MailHostError as e: log.error("MailHost error sending email confirmation to %s: %s", account.email, e) flash(_("An error occured while sending the confirmation email."), "error") return False except smtplib.SMTPException as e: log.error( "smtplib error sending the confirmation email to %s: %s", account.email, e, ) flash(_("An error occured while sending the confirmation email."), "error") return False except socket.error as e: log.error("Socket error sending confirmation email to %s: %s", account.email, e[1]) flash(_("An error occured while sending the confirmation email."), "error") return False return True
def testLength(self): self.assertEqual(len(utils.randomString(5)), 5)
def testOutputChanges(self): self.assertNotEqual(utils.randomString(), utils.randomString())