def __init__(self, *args): Controller.__init__(self, *args) self.goals = {} self.mission = Operate(self) self.move_propose = [] self.move_pos = self.puppet.pos self.mover = None self.move_score = 0 self.move_time = 0.0 self.magic_propose = [] self.magic_casters = {} self.waypoint = self.puppet.pos
def init_controller(app): controllers = Controller.__subclasses__() for controller in controllers: controller.init(app) app.jinja_env.globals.update({ controller.__name__: controller })
def open_submit(self, election, encrypted_vote, email=None, openid_url=None, name=None, category=None): """ Submitting a vote in an open election """ if not election.openreg_enabled: self.error("Election not open") api_client = do.APIClient.get_by_consumer_key(Controller.api_client()) if not api_client or election.api_client.api_client_id != api_client.api_client_id: logging.info(api_client) self.error("Bad Authentication") # API client is authenticated to manage this election # see if there is already a voter for this email and/or openid_url voter= do.Voter.selectByEmailOrOpenID(election, email, openid_url) if not voter: voter = do.Voter() voter.election = election voter.insert() # set parameters that may be updates to the existing voter voter.email = email voter.openid_url = openid_url voter.name = name voter.category = category voter.save() # set the encrypted vote voter.set_encrypted_vote(encrypted_vote) return voter.voter_id
def controllers(model): _controllers = [controller for controller in Controller.__subclasses__() if controller.model == model] if len(_controllers) > 1: raise RuntimeError('Too many controllers with the same model: %s' % model) return _controllers.pop()
def new_2(self, name, election_type): """ Enter additional information about the election type. """ user = Controller.user() eg_params_json = utils.to_json(ELGAMAL_PARAMS.toJSONDict()) return self.render('new_2')
def check(cls, election, allow_frozen=False, require_frozen=False): """ An internal check that the user is allowed to administer this given election. Optional parameters check the status of the election. """ user = Controller.user() api_client = do.APIClient.get_by_consumer_key(Controller.api_client()) if user != election.admin and api_client != election.api_client: raise cherrypy.HTTPRedirect('/') if election.is_frozen() and not allow_frozen: raise cherrypy.HTTPError(500, 'This election is frozen and cannot be modified.') if not election.is_frozen() and require_frozen: raise cherrypy.HTTPError(500, "Election must be frozen before emailing voters.") return user, api_client, election
def check(cls, election, allow_frozen=False, require_frozen=False): """ An internal check that the user is allowed to administer this given election. Optional parameters check the status of the election. """ user = Controller.user() api_client = do.APIClient.get_by_consumer_key(Controller.api_client()) if user != election.admin and api_client != election.api_client: raise cherrypy.HTTPRedirect('/') if election.is_frozen() and not allow_frozen: raise cherrypy.HTTPError( 500, 'This election is frozen and cannot be modified.') if not election.is_frozen() and require_frozen: raise cherrypy.HTTPError( 500, "Election must be frozen before emailing voters.") return user, api_client, election
def open_submit(self, election, encrypted_vote, email=None, openid_url=None, name=None, category=None): """ Submitting a vote in an open election """ if not election.openreg_enabled: self.error("Election not open") api_client = do.APIClient.get_by_consumer_key(Controller.api_client()) if not api_client or election.api_client.api_client_id != api_client.api_client_id: logging.info(api_client) self.error("Bad Authentication") # API client is authenticated to manage this election # see if there is already a voter for this email and/or openid_url voter = do.Voter.selectByEmailOrOpenID(election, email, openid_url) if not voter: voter = do.Voter() voter.election = election voter.insert() # set parameters that may be updates to the existing voter voter.email = email voter.openid_url = openid_url voter.name = name voter.category = category voter.save() # set the encrypted vote voter.set_encrypted_vote(encrypted_vote) return voter.voter_id
def debug_info(self): return "%s dir=[%.1f,%.1f]" % \ (Controller.debug_info(self), self.xdiff, self.ydiff)
def __init__(self, *args): Controller.__init__(self, *args) self.xdiff = self.ydiff = 0.0
def new_3(self, name, trustee = None, public_key=None, private_key=None, voting_starts_at=None, voting_ends_at=None, **kw): """ Create the new election. trustees is a JSON list """ # we need a list of admins, or at least a public key if not trustee and not public_key: self.error('Need a list of trustees or a public key') election = do.Election() # hard-wire the type for now, we only have one type of election election.election_type = 'homomorphic' # basic election parameters election.name = name election.admin, election.api_client = self.user(), do.APIClient.get_by_consumer_key(Controller.api_client()) election.voting_starts_at = utils.string_to_datetime(voting_starts_at) election.voting_ends_at = utils.string_to_datetime(voting_ends_at) # serialize the public key to JSON and store it if it was sent if public_key and public_key != "": pk = algs.EGPublicKey.from_dict(utils.from_json(public_key)) election.public_key_json = utils.to_json(pk.to_dict()) # the private key can be stored by the server if private_key and private_key != "": sk = algs.EGSecretKey.from_dict(utils.from_json(private_key)) election.private_key_json = utils.to_json(sk.to_dict()) ## FIXME: transaction! election.save() # go through the trustees if trustee: for t in trustee: if t.strip() == "": continue # create the keyshare keyshare = do.KeyShare() keyshare.parent = election keyshare.election = election keyshare.email = t keyshare.generate_password() keyshare.save() # send out the email self.email_trustees_2(election, 'You have been designated as a trustee of the Helios Election "%s".' % election.name) # user or api_client? if election.admin: raise cherrypy.HTTPRedirect("./%s/view" % str(election.election_id)) else: return str(election.election_id)
def new_3(self, name, trustee=None, public_key=None, private_key=None, voting_starts_at=None, voting_ends_at=None, **kw): """ Create the new election. trustees is a JSON list """ # we need a list of admins, or at least a public key if not trustee and not public_key: self.error('Need a list of trustees or a public key') election = do.Election() # hard-wire the type for now, we only have one type of election election.election_type = 'homomorphic' # basic election parameters election.name = name election.admin, election.api_client = self.user( ), do.APIClient.get_by_consumer_key(Controller.api_client()) election.voting_starts_at = utils.string_to_datetime(voting_starts_at) election.voting_ends_at = utils.string_to_datetime(voting_ends_at) # serialize the public key to JSON and store it if it was sent if public_key and public_key != "": pk = algs.EGPublicKey.from_dict(utils.from_json(public_key)) election.public_key_json = utils.to_json(pk.to_dict()) # the private key can be stored by the server if private_key and private_key != "": sk = algs.EGSecretKey.from_dict(utils.from_json(private_key)) election.private_key_json = utils.to_json(sk.to_dict()) ## FIXME: transaction! election.save() # go through the trustees if trustee: for t in trustee: if t.strip() == "": continue # create the keyshare keyshare = do.KeyShare() keyshare.parent = election keyshare.election = election keyshare.email = t keyshare.generate_password() keyshare.save() # send out the email self.email_trustees_2( election, 'You have been designated as a trustee of the Helios Election "%s".' % election.name) # user or api_client? if election.admin: raise cherrypy.HTTPRedirect("./%s/view" % str(election.election_id)) else: return str(election.election_id)