Skip to content

Commit

Permalink
number of small fixes and ability to email voters from the python client
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Adida authored and Ben Adida committed Jun 1, 2009
1 parent c2e724b commit 6af7e33
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 17 deletions.
4 changes: 2 additions & 2 deletions client/electioncreator.py → client/createlection.py
Expand Up @@ -2,7 +2,7 @@
Create an Election
usage:
python client/electioncreator.py ELECTION_NAME election_questions.json voters.csv HELIOS_SERVER API_KEY_FILENAME.json SECRET_KEY_FILENAME.txt
python client/creationelection.py ELECTION_NAME election_questions.json voters.csv HELIOS_SERVER API_KEY_FILENAME.json SECRET_KEY_FILENAME.txt
"""

from base import utils
Expand Down Expand Up @@ -37,7 +37,7 @@ def open_and_read_file(file_path):
# api_key_file should contain {consumer_key: 'test', consumer_secret: 'test', access_token: '123', access_token_secret : '123'}
helios = heliosclient.HeliosClient(api_key,
host = HELIOS_SERVER,
port = 8080)
port = 80)

# get the El Gamal Parameters
params = helios.params()
Expand Down
51 changes: 51 additions & 0 deletions client/emailvoters.py
@@ -0,0 +1,51 @@
"""
Send Email to Voters
usage:
python client/emailvoters.py HELIOS_SERVER ELECTION_ID API_KEY_FILE.json SUBJECT_FILE.txt BODY_FILE.txt
"""

from base import utils
from crypto import algs, electionalgs
from client import heliosclient

import sys

HELIOS_SERVER = sys.argv[1]
ELECTION_ID = sys.argv[2]
API_KEY_FILE = sys.argv[3]
SUBJECT_FILE = sys.argv[4]
BODY_FILE = sys.argv[5]

def open_and_read_file(file_path):
the_file = open(file_path, "r")
the_content = the_file.read()
the_file.close()
return the_content

# parse the json for api keys
api_key = utils.from_json(open_and_read_file(API_KEY_FILE))

# instantiate the client
helios = heliosclient.HeliosClient(api_key,
host = HELIOS_SERVER,
port = 80)

last_voter_id = None
LIMIT = 10

subject = open_and_read_file(SUBJECT_FILE)
body = open_and_read_file(BODY_FILE)

while True:
print "LAST VOTER ID is %s" % str(last_voter_id)

# send the the email
res = helios.election_voters_send_email(ELECTION_ID, subject = subject, body = body, after = last_voter_id, limit = LIMIT)
print "res is " + res

if res == "DONE":
break

# increment offset by LIMIT, continue
last_voter_id = res
24 changes: 24 additions & 0 deletions client/heliosclient.py
Expand Up @@ -51,6 +51,30 @@ def election_freeze(self, election_id):
result = self.post("/elections/%s/freeze_2" % election_id, {})
return result == "SUCCESS"

def election_voters(self, election_id, after=None, limit=None):
params = {}
if after:
params['after'] = str(after)
if limit:
params['limit'] = str(limit)

print params
result = self.get("/elections/%s/voters/" % election_id, params)
print result
return utils.from_json(result)

def election_voters_send_email(self, election_id, subject, body, voter_ids=None, after=None, limit=None):
params = {'introductory_message' : body}
if voter_ids:
params['voter_ids'] = ",".join([str(v) for v in voter_ids])
if after:
params['after'] = after
if limit:
params['limit'] = str(limit)

result = self.post("/elections/%s/voters_email_2" % election_id, params)
return result

def open_submit(self, election_id, encrypted_vote, email=None, openid_url=None, name=None, category=None):
"""
encrypted_vote is a JSON string
Expand Down
6 changes: 6 additions & 0 deletions client/oauthclient.py
Expand Up @@ -29,6 +29,12 @@ def access_resource(self, method, url, parameters):
headers['Content-Length'] = 0

#print "headers: " + str(headers)

if method == "GET" and parameters:
param_string = utils.dictToURLParams(parameters)
if param_string != '':
url += '?' + param_string
parameters = {}

connection = httplib.HTTPConnection("%s:%d" % (self.server, self.port))
connection.request(method, url, headers= headers, body = utils.dictToURLParams(parameters))
Expand Down
27 changes: 14 additions & 13 deletions controllers/election.py
Expand Up @@ -140,7 +140,7 @@ def submit(self, voter, email, password, encrypted_vote):
The Helios Voting System
""" % (voter.name, election_obj.name, voter.get_vote_hash(), election_obj.hash)

mail.simple_send([voter.name],[voter.email], "Helios", "ben@adida.net", "your vote was recorded", mail_body)
mail.simple_send([voter.name],[voter.email], "Helios", "system@heliosvoting.org", "your vote was recorded", mail_body)

return SUCCESS

Expand Down Expand Up @@ -458,20 +458,21 @@ def send_password(self, election, email):

# send a confirmation email
mail_body = """
Dear %s,
Dear %s,
You requested a copy of your election password for election %s. It is:
You requested a copy of your election password for election %s. It is:
%s
%s
And, as a reminder, the fingerprint of the election itself is:
%s
And, as a reminder, the fingerprint of the election itself is:
--
The Helios Voting System
""" % (voter.name, election_obj.name, voter.password, election_obj.hash)
%s
--
The Helios Voting System
""" % (voter.name, election_obj.name, voter.password, election_obj.hash)

mail.simple_send([voter.name],[voter.email], "Helios", "ben@adida.net", "password reminder", mail_body)
mail.simple_send([voter.name],[voter.email], "Helios", "system@heliosvoting.org", "password reminder", mail_body)

return SUCCESS

Expand Down Expand Up @@ -751,7 +752,7 @@ def voters_email_2(self, election, introductory_message, voter_ids=None, after=N
if user:
sender_email = user.email_address
else:
sender_email = "ben@adida.net"
sender_email = "system@heliosvoting.org"

for voter in voters:
logging.info("sending email to %s" % voter.email)
Expand All @@ -771,7 +772,7 @@ def voters_email_2(self, election, introductory_message, voter_ids=None, after=N
--
%s
via the Helios Voting System
Helios Voting System
www.heliosvoting.org
""" % ((config.webroot + '/elections/%s/view')%election.election_id, (config.webroot + '/elections/%s/vote')%election.election_id, election.toElection().get_hash(), voter.email, voter.password, sender_email)

Expand Down Expand Up @@ -823,7 +824,7 @@ def email_trustees_2(self, election, body):
full_body = message % (body, election.name, config.webroot + ('/elections/%s/trustees/%s/home' % (election.election_id, utils.urlencode(trustee.email))), trustee.password)

# send out the emails for the shares
mail.simple_send([trustee.email],[trustee.email],"Helios","ben@adida.net", subject, full_body)
mail.simple_send([trustee.email],[trustee.email],"Helios","system@heliosvoting.org", subject, full_body)

return "DONE"

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 23 times in query history.
# Unused in query history -- copied from input.
- kind: ElectionExponent
properties:
- name: election
Expand Down Expand Up @@ -43,7 +43,7 @@ indexes:
- name: tallied_at
- name: cast_id

# Used 3 times in query history.
# Unused in query history -- copied from input.
- kind: Voter
properties:
- name: election
Expand Down

0 comments on commit 6af7e33

Please sign in to comment.