def test_suite(): from bungeni.core.app import BungeniApp # NOTE: to run an individual test txt file from the commandline: # # $ bin/test -s bungeni.core -t file.txt # doctests = ('audit.txt', 'version.txt', 'odf.txt', 'workflows/question.txt', 'workflows/motion.txt', 'workflows/bill.txt', 'workflows/transitioncron.txt', ) docfiles = ("bungeni.core.transformation",) # set up global symbols for doctests today = datetime.date.today() globs = dict( interface=interface, component=component, datetime=datetime, os=os, copy=copy, app=BungeniApp(), today=today, yesterday=today-datetime.timedelta(1), daybeforeyesterday=today-datetime.timedelta(2), tomorrow=today+datetime.timedelta(1), dayat=today+datetime.timedelta(2), path=os.path.dirname(__file__), ) test_suites = [] for filename in doctests: test_suite = doctestunit.DocFileSuite( os.path.join(os.path.pardir, filename), setUp = setUp, tearDown = tearDown, globs = globs, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) test_suites.append(test_suite) for filename in docfiles: test_suite = doctestunit.DocTestSuite( filename, setUp=setUp, tearDown=tearDown, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) test_suites.append(test_suite) return unittest.TestSuite( test_suites )
def handle_restore(self, action, data): site_url = ui_utils.url.absoluteURL(getSite(), self.request) login = data.get("login", "") email = data.get("email", "") user = None app = BungeniApp() settings = EmailSettings(app) session = Session() if email: user = session.query(User).filter( User.email==email).first() elif login: user = session.query(User).filter( User.login==login).first() if user: email = user.email link = session.query(PasswordRestoreLink).filter( PasswordRestoreLink.user_id==user.user_id).first() if link: if not link.expired(): self.status = _(u"This user's link is still active!") return else: link = PasswordRestoreLink() link.hash = hashlib.sha224(user.login + SECRET_KEY + str(datetime.datetime.now())).hexdigest() link.expiration_date = datetime.datetime.now() + datetime.timedelta(1) link.user_id = user.user_id session.add(link) mailer = getUtility(ISMTPMailer, name="bungeni.smtp") self.message = _(u"Restore password link: ")\ + "%s/reset_password?key=%s" % (site_url, link.hash) self.message += u"\n\n" self.message += _(u"This link will expire in 24 hours.") text = ViewPageTemplateFile("templates/mail.pt")(self) message = MIMEText(text) message.set_charset("utf-8") message["Subject"] = _(u"Bungeni password restoration") message["From"] = settings.default_sender mailer.send(settings.default_sender, email, str(message)) self.status = _(u"Email was sent!") else: self.status = _(u"User not found!")
def handle_restore(self, action, data): email = data.get("email", "") if email: app = BungeniApp() settings = EmailSettings(app) session = Session() user = session.query(User).filter(User.email == email).first() if user: mailer = getUtility(IBungeniMailer) self.message = _(u"Your login is: ") + user.login text = ViewPageTemplateFile("templates/mail.pt")(self) message = MIMEText(text) message.set_charset("utf-8") message["Subject"] = _(u"Bungeni login restoration") message["To"] = email mailer.send(message) self.status = _(u"Your login was sent to you email.") else: self.status = _(u"Wrong email address.")
import smtplib import zope.interface import zope.sendmail.interfaces import logging from bungeni.core.app import BungeniApp from bungeni.models.settings import EmailSettings app = BungeniApp() class SMTPMailer(object): """A direct mailer for use with zope.sendmail.""" zope.interface.implements(zope.sendmail.interfaces.ISMTPMailer) def get_settings(self): return EmailSettings(app) def send(self, fromaddr, toaddrs, message): settings = self.get_settings() hostname = settings.hostname port = settings.port username = settings.username or None password = settings.password or None fromaddr = fromaddr or settings.default_sender connection = smtplib.SMTP(hostname, port) if settings.use_tls: connection.ehlo() connection.starttls() connection.ehlo() # authenticate if needed
def get_group_context(context): if interfaces.IOffice.providedBy(context): return BungeniApp() #get_parliament(context) else: return removeSecurityProxy(context)