Ejemplo n.º 1
0
 def verify_token(self):
     token = self.request.matchdict['token']
     if self.request.settings.archive_mode:
         result = '1'
     elif self.request.settings.ctf_state == CTF_BEFORE:
         result = '0'
     else:
         try:
             get_active_teams().filter(Team.challenge_token == token).one()
         except NoResultFound:
             result = '0'
         else:
             result = '1'
     return Response(result)
Ejemplo n.º 2
0
 def test_get_active_teams(self):
     t1 = self.make_team(active=True)
     t2 = self.make_team()
     self.dbsession.add_all([t1, t2])
     q = get_active_teams()
     assert q.count() == 1
     assert q.first() == t1
Ejemplo n.º 3
0
 def massmail(self):
     """
     Send a massmail to all users in the system. It also stores the sent
     mail and its recipients in the database to keep a permanent record of
     sent messages.
     """
     form = MassMailForm(self.request.POST, csrf_context=self.request)
     if not form.from_.data:
         settings = self.request.registry.settings
         form.from_.data = settings["mail.default_sender"]
     mail_query = DBSession.query(MassMail)
     page = self.page(mail_query)
     retparams = {"form": form, "items": page.items, "page": page}
     if self.request.method == "POST":
         if not form.validate():
             return retparams
         teams = get_active_teams()
         # Create a record to keep track of all sent mails
         mail_record = MassMail()
         form.populate_obj(mail_record)
         recipients = [team.email for team in teams]
         mail_record.recipients = recipients
         mailer = get_mailer(self.request)
         message = Message(
             subject=mail_record.subject,
             bcc=mail_record.recipients,
             body=mail_record.message,
             sender=mail_record.from_,
         )
         DBSession.add(mail_record)
         mailer.send(message)
         self.request.session.flash("Mass mail sent to all %d active users" % len(recipients))
         return HTTPFound(location=self.request.route_url("admin_massmail"))
     return retparams
Ejemplo n.º 4
0
 def teams(self):
     """
     Only a list of teams.
     """
     return {'teams': list(get_active_teams())}