Exemple #1
0
    def voters_bulk_upload(self, election, voters_csv):
        """
    Process a bulk upload form for voters
    """
        user, api_client, election = self.check(
            election,
            allow_frozen=(election.openreg_enabled
                          and not election.result_json))

        voters_csv_lines = voters_csv.split("\n")
        reader = csv.reader(voters_csv_lines)

        for voter in reader:

            if len(voter) < 2:
                continue

            # process the CSV and add
            v = do.Voter()
            v.election = election
            v.email = voter[1]
            v.name = voter[0]
            if len(voter) > 2:
                v.category = voter[2]
            v.generate_password()
            v.insert()

        return self.redirect("./voters_manage")
Exemple #2
0
    def test_create_password_voter(self):
        v = models.Voter(uuid = str(uuid.uuid1()), election = self.election, voter_login_id = 'voter_test_1', voter_name = 'Voter Test 1', voter_email='*****@*****.**')

        v.generate_password()

        v.save()
        
        # password has been generated!
        self.assertFalse(v.voter_password == None)

        # can't generate passwords twice
        self.assertRaises(Exception, lambda: v.generate_password())
        
        # check that you can get at the voter user structure
        self.assertEquals(v.user.user_id, v.voter_email)
Exemple #3
0
    def add(self, email, name, category=None):
        """
    Add a new voter to an election.
    """
        user, api_client, election = ElectionController.check(
            self.parent,
            allow_frozen=(self.parent.openreg_enabled
                          and not self.parent.result_json))

        v = do.Voter()
        v.election = election
        v.email = email
        v.name = name
        v.category = category
        v.generate_password()
        v.insert()

        raise cherrypy.HTTPRedirect("../voters_manage")
Exemple #4
0
    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
Exemple #5
0
 def REST_create(self, voter_id):
     return do.Voter()