Skip to content

Commit

Permalink
added ability to email trustees
Browse files Browse the repository at this point in the history
  • Loading branch information
benadida committed Sep 14, 2008
1 parent 51e9725 commit b70bbcd
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 18 deletions.
54 changes: 38 additions & 16 deletions controllers/election.py
Expand Up @@ -350,22 +350,8 @@ def new_3(self, name, trustee = None, public_key=None, private_key=None, voting_
keyshare.generate_password()
keyshare.save()

# the message to email
message = """
You have been designated as a trustee of the Helios Election "%s".
Go create your key and manage your contribution at the following URL:
%s
Your password is:
%s
--
The Helios Voting System
""" % (election.name, config.webroot + ('/elections/%s/trustees/%s/home' % (election.election_id, utils.urlencode(keyshare.email))), keyshare.password)

# send out the emails for the shares
mail.simple_send([keyshare.email],[keyshare.email],"Helios","ben@adida.net","Trustee Information for %s" % election.name, message)
# send out the email
self.email_trustees_2(election, 'Trustee Information for %s' % election.name, 'You have been designated as a trustee of the Helios Election "%s".' % election.name)

# user or api_client?
if election.admin:
Expand Down Expand Up @@ -641,6 +627,42 @@ def email_voters_2(self, election, introductory_message):
# hack for now, no more batching
return "DONE"

@web
@session.login_protect
def email_trustees(self, election):
keyshares = election.get_keyshares()
return self.render('email_trustees')

@web
@session.login_protect
def email_trustees_2(self, election, body):
user, api_client, election = self.check(election, True, True)

# the message to email
message = """
%s
Your Trustee homepage for election "%s" is:
%s
Your password is:
%s
--
The Helios Voting System
"""

subject = "Trustee Information for %s" % election.name

trustees = election.get_keyshares()
for trustee in trustees:
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)

return "DONE"

@web
@session.login_protect
def compute_tally(self, election):
Expand Down
4 changes: 2 additions & 2 deletions index.yaml
Expand Up @@ -17,7 +17,7 @@ indexes:
- name: exponent
direction: desc

# Used 105 times in query history.
# Used 110 times in query history.
- kind: KeyShare
properties:
- name: election
Expand All @@ -43,7 +43,7 @@ indexes:
- name: tallied_at
- name: cast_id

# Used 186 times in query history.
# Used 199 times in query history.
- kind: Voter
properties:
- name: election
Expand Down
58 changes: 58 additions & 0 deletions templates/election/email_trustees.tmpl
@@ -0,0 +1,58 @@
#include "templates/header.tmpl"

<script>
function send_email() {
var form = document.forms['email_form'];

\$.post("email_trustees_2", {'body' : form.body.value}, function(data) {
// decide whether or not to keep going
if (data != "DONE") {
alert('oy unexpected: ' + data);
} else {
alert('done!');
document.location = "./view";
}
});
}
</script>

<h2>$election.name: Email Voters &mdash; Email Trustees</h2>

<p>
You are about to email the trustees in this election:
</p>

<ul>
#for $keyshare in $keyshares
<li> <tt>$keyshare.email</tt></li>
#end for
</ul>

<blockquote>
<form name="email_form" method="post" onsubmit="try {send_email();} catch(e) {alert(e);} return false;">

<pre>
Dear [TRUSTEE_NAME],
</pre>

<textarea name="body" cols="60" rows="10" wrap="soft" class="pretty">
</textarea>
<pre>
Your Trustee homepage for election [ELECTION_NAME] is:
[TRUSTEE_HOMEPAGE]

Your password is:
[TRUSTEE_PASSWORD]
</pre>

</blockquote>

<br />
<br /><br />
<input type="submit" value="send now!" class="pretty" />
</form>

</div>

<!-- end #content -->
#include "templates/footer.tmpl"
4 changes: 4 additions & 0 deletions templates/election/one.tmpl
Expand Up @@ -54,6 +54,10 @@
<br /><li> <a href="email_voters">email voters</a></li>
#end if

#if len($election.get_keyshares()) > 0
<li> <a href="email_trustees">email trustees</a></li>
#end if

#if not $election.archived_at
<br /><li> <a href="archive">archive election</a></li>
#else
Expand Down

0 comments on commit b70bbcd

Please sign in to comment.