Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Helios Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Helios Server
Commits
2f76151a
Commit
2f76151a
authored
Aug 3, 2009
by
Ben Adida
Browse files
Options
Downloads
Patches
Plain Diff
added casting for IACR election
parent
b4a7421e
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
iacr/templates/confirm.html
+29
-0
29 additions, 0 deletions
iacr/templates/confirm.html
iacr/templates/done.html
+17
-0
17 additions, 0 deletions
iacr/templates/done.html
iacr/urls.py
+3
-1
3 additions, 1 deletion
iacr/urls.py
iacr/views.py
+77
-10
77 additions, 10 deletions
iacr/views.py
with
126 additions
and
11 deletions
iacr/templates/confirm.html
0 → 100644
+
29
−
0
View file @
2f76151a
{% extends 'iacr/templates/base.html' %}
{% block title %}Confirm Vote{% endblock %}
{% block content %}
<h1>
Confirm your Vote
</h1>
{% if error %}
<p
style=
"color: red;"
>
{{error}}
</p>
{% endif %}
<h3>
Your Ballot
</h3>
<p
style=
"font-size:1.6em;"
>
<tt>
{{vote_fingerprint}}
</tt>
</p>
<h3>
Cast Your Ballot with your Credentials
</h3>
<form
method=
"post"
action=
""
>
<input
type=
"hidden"
name=
"csrf_token"
value=
"{{csrf_token}}"
/>
<table>
{{form.as_table}}
</table><br
/>
<input
type=
"submit"
value=
"cast this ballot"
/><br
/><br
/>
</form>
{% endblock %}
This diff is collapsed.
Click to expand it.
iacr/templates/done.html
0 → 100644
+
17
−
0
View file @
2f76151a
{% extends 'iacr/templates/base.html' %}
{% block title %}Confirm Vote{% endblock %}
{% block content %}
<h1>
Your Vote was Cast
</h1>
<p>
A vote was successfully cast for
<b>
{{voter.voter_id}}
</b>
, with vote fingerprint:
<br
/><br
/>
<tt
style=
"font-size: 2em;"
>
{{voter.vote_hash}}
</tt>
</p>
<p>
Visit the
<a
href=
"{% url helios.views.one_election_view election.uuid %}"
>
election homepage
</a>
.
</p>
{% endblock %}
This diff is collapsed.
Click to expand it.
iacr/urls.py
+
3
−
1
View file @
2f76151a
...
...
@@ -6,5 +6,7 @@ from views import *
urlpatterns
=
patterns
(
''
,
(
r
'
^$
'
,
home
),
(
r
'
^about$
'
,
about
),
(
r
'
^cast$
'
,
cast
)
(
r
'
^cast$
'
,
cast
),
(
r
'
^confirm$
'
,
cast_confirm
),
(
r
'
^done$
'
,
cast_done
),
)
This diff is collapsed.
Click to expand it.
iacr/views.py
+
77
−
10
View file @
2f76151a
...
...
@@ -8,24 +8,32 @@ from view_utils import *
import
helios.views
import
helios
from
helios.crypto
import
utils
as
cryptoutils
from
django.core.urlresolvers
import
reverse
from
django.http
import
HttpResponse
,
HttpResponseRedirect
,
Http404
,
HttpResponseNotAllowed
ELECTION_SHORT_NAME
=
'
iacr09
'
def
get_election
():
return
Election
.
get_by_key_name
(
ELECTION_SHORT_NAME
)
def
home
(
request
):
# create the election if need be
election_params
=
{
'
short_name
'
:
'
iacr09
'
,
'
short_name
'
:
ELECTION_SHORT_NAME
,
'
name
'
:
'
IACR 2009 Election
'
,
'
description
'
:
'
Election for the IACR Board - 2009
'
,
'
uuid
'
:
'
iacr
'
,
'
cast_url
'
:
reverse
(
cast
),
'
self_registration
'
:
False
,
'
openreg
'
:
False
,
'
admin
'
:
helios
.
ADMIN
'
admin
'
:
helios
.
ADMIN
,
'
tally_type
'
:
'
homomorphic
'
,
'
ballot_type
'
:
'
homomorphic
'
}
election
=
Election
.
get_by_key_name
(
election_params
[
'
short_name
'
]
)
election
=
get_election
(
)
if
not
election
:
election
=
Election
(
key_name
=
election_params
[
'
short_name
'
],
**
election_params
)
election
.
put
()
...
...
@@ -35,12 +43,71 @@ def home(request):
def
about
(
request
):
return
HttpResponse
(
request
,
"
about
"
)
@helios.views.election_view
(
frozen
=
True
)
def
cast
(
request
,
election
):
if
request
.
method
==
"
GET
"
:
def
cast
(
request
):
encrypted_vote
=
request
.
POST
[
'
encrypted_vote
'
]
request
.
session
[
'
encrypted_vote
'
]
=
encrypted_vote
return
render_template
(
request
,
"
cast
"
,
{
'
election
'
:
election
})
return
HttpResponseRedirect
(
reverse
(
cast_confirm
))
# the form for password login
from
auth.auth_systems.password
import
LoginForm
,
password_check
def
cast_confirm
(
request
):
election
=
get_election
()
if
not
election
.
frozen_at
or
election
.
result
:
return
HttpResponse
(
"
election is not ready or already done
"
)
encrypted_vote
=
request
.
session
[
'
encrypted_vote
'
]
vote_fingerprint
=
cryptoutils
.
hash_b64
(
encrypted_vote
)
error
=
None
if
request
.
method
==
"
GET
"
:
form
=
LoginForm
()
else
:
# do the casting
pass
form
=
LoginForm
(
request
.
POST
)
if
form
.
is_valid
():
user
=
User
.
get_by_type_and_id
(
'
password
'
,
form
.
cleaned_data
[
'
username
'
])
if
password_check
(
user
,
form
.
cleaned_data
[
'
password
'
]):
# cast the actual vote
voter
=
Voter
.
get_by_election_and_user
(
election
,
user
)
if
not
voter
:
return
HttpResponse
(
"
problem, you are not registered for this election
"
)
# prepare the vote to cast
cast_vote_params
=
{
'
vote
'
:
electionalgs
.
EncryptedVote
.
fromJSONDict
(
utils
.
from_json
(
encrypted_vote
)),
'
voter
'
:
voter
,
'
vote_hash
'
:
vote_fingerprint
,
'
cast_at
'
:
datetime
.
datetime
.
utcnow
(),
'
election
'
:
election
}
cast_vote
=
CastVote
(
**
cast_vote_params
)
# verify the vote
if
cast_vote
.
vote
.
verify
(
election
):
# store it
voter
.
store_vote
(
cast_vote
)
else
:
return
HttpResponse
(
"
vote does not verify:
"
+
utils
.
to_json
(
cast_vote
.
vote
.
toJSONDict
()))
# remove the vote from the store
del
request
.
session
[
'
encrypted_vote
'
]
return
HttpResponseRedirect
(
reverse
(
cast_done
)
+
'
?email=
'
+
voter
.
voter_id
)
else
:
error
=
'
Bad Username or Password
'
return
render_template
(
request
,
"
confirm
"
,
{
'
election
'
:
election
,
'
vote_fingerprint
'
:
vote_fingerprint
,
'
error
'
:
error
,
'
form
'
:
form
})
def
cast_done
(
request
):
email
=
request
.
GET
[
'
email
'
]
election
=
get_election
()
user
=
User
.
get_by_type_and_id
(
'
password
'
,
email
)
voter
=
Voter
.
get_by_election_and_user
(
election
,
user
)
past_votes
=
CastVote
.
get_by_election_and_voter
(
election
,
voter
)
return
render_template
(
request
,
'
done
'
,
{
'
election
'
:
election
,
'
past_votes
'
:
past_votes
,
'
voter
'
:
voter
})
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment