Skip to content

Commit

Permalink
added submission of vote by OAuth proxy.
Browse files Browse the repository at this point in the history
  • Loading branch information
benadida committed Aug 31, 2008
1 parent 2d3a178 commit d55fc95
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 8 deletions.
15 changes: 14 additions & 1 deletion client/admin.py
Expand Up @@ -45,6 +45,15 @@ def election_freeze(self, election_id):
result = self.post("/elections/%s/freeze_2" % election_id, {})
return result == "SUCCESS"

def open_submit(self, election_id, encrypted_vote, email=None, openid_url=None, name=None, category=None):
"""
encrypted_vote is a JSON string
"""
result = self.post("/elections/%s/open_submit" % election_id, {'encrypted_vote' : encrypted_vote, 'email': email,
'openid_url' : openid_url, 'name' : name, 'category' :category})

return result

def set_tally(self, election_id, result, result_proof):
tally_obj = {'result' : result, 'result_proof' : result_proof}
tally_obj_json = utils.to_json(tally_obj)
Expand Down Expand Up @@ -72,4 +81,8 @@ def set_tally(self, election_id, result, result_proof):
print helios.election_set_reg(election_id, open_reg= True)

# freeze it
print helios.election_freeze(election_id)
print helios.election_freeze(election_id)

# open submit a couple of votes
print helios.open_submit(election_id, '{"foo":"bar"}', 'ben@adida.net', None, 'Ben Adida', 'Foo Category')
print helios.open_submit(election_id, '{"foo":"bazzz"}', 'ben2@adida.net', 'http://benadida.myopenid.com', 'Ben2 Adida', 'Bar Category')
29 changes: 24 additions & 5 deletions controllers/election.py
Expand Up @@ -280,20 +280,39 @@ def voters_manage(self, election):
return self.render('voters')

@web
def open_submit(self, election, encrypted_vote, email=None, openid_url=None):
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 = Controller.api_client()
if not api_client or election.api_client != api_client:
self.error("Bad Authentication Authentication")
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
# CREATE a voter and add it, recording the encrypted vote
# FIXME: work here

# 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

@web
@session.login_protect
Expand Down
4 changes: 2 additions & 2 deletions index.yaml
Expand Up @@ -10,7 +10,7 @@ indexes:
# automatically uploaded to the admin console when you next deploy
# your application using appcfg.py.

# Used 3 times in query history.
# Used 8 times in query history.
- kind: ElectionExponent
properties:
- name: election
Expand All @@ -37,7 +37,7 @@ indexes:
- name: tallied_at
- name: cast_id

# Used 27 times in query history.
# Used 29 times in query history.
- kind: Voter
properties:
- name: election
Expand Down
2 changes: 2 additions & 0 deletions models/modelsGAE.py
Expand Up @@ -33,6 +33,8 @@ class APIClient(mbase.APIClient):
consumer_secret = db.StringProperty()
access_token = db.StringProperty()
access_token_secret = db.StringProperty()

api_client_id = property(DBObject.get_id)

class Election(mbase.ElectionBase):
admin = db.UserProperty()
Expand Down
16 changes: 16 additions & 0 deletions models/modelsbase.py
Expand Up @@ -327,6 +327,22 @@ def get_exp(cls, election, value):
class VoterBase(DBObject):
JSON_FIELDS = ['voter_id','name', 'email']

@classmethod
def selectByEmailOrOpenID(cls, election, email, openid_url):
email_voter = openid_voter = None

if email:
email_voter = cls.selectByKeys({'election': election, 'email': email})

if openid_url:
openid_voter = cls.selectByKeys({'election': election, 'openid_url': openid_url})

# two voters, not the same?
if email_voter and openid_voter and email_voter.voter_id != openid_voter.voter_id:
raise Exception("problem matching openid and email")

return email_voter or openid_voter

def save(self):
if not self.is_saved():
# add an election exponent
Expand Down

0 comments on commit d55fc95

Please sign in to comment.