2017-11-23 23:10:57 +11:00
{% extends templates['booth/base.html'] %}
{#
Eos - Verifiable elections
2018-01-08 00:01:07 +11:00
Copyright © 2017-18 RunasSudo (Yingtong Li)
2017-11-23 23:10:57 +11:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see < http: / / www . gnu . org / licenses / > .
#}
{% block content %}
< div id = "cast_prompt" >
2018-01-08 23:16:28 +11:00
< p > Your vote has < span class = "superem" > not< / span > yet been cast. If you have not already done so, please make a note of your ballot fingerprint, < span class = "hash" > {{ eosjs.eos.core.hashing.__all__.SHA256().update_obj(ballot).hash_as_b64(true) }}< / span > .< / p >
2017-11-28 12:57:45 +11:00
< div class = "ui negative message" >
2017-11-28 14:45:05 +11:00
< p > Your vote has < span class = "superem" > not< / span > yet been cast. Please follow the instructions to continue.< / p >
2017-11-28 12:57:45 +11:00
< / div >
2017-11-25 23:16:29 +11:00
< p > This election requires you to log in to vote. If you disconnected your internet connection earlier, you must now reconnect it before proceeding.< / p >
{% if username %}
2017-11-26 11:17:28 +11:00
< p > < span id = "booth_logged_in_as" > You are currently logged in as {{ username }}.< / span > Please select an option from the list below if you would like to switch accounts. Otherwise, click ‘Cast ballot’ to continue.< / p >
2017-11-25 23:16:29 +11:00
{% else %}
2017-11-26 11:17:28 +11:00
< p > < span id = "booth_logged_in_as" > You are not currently logged in.< / a > Please select an option from the list below to log in. Your ballot will be automatically cast once you have logged in.< / p >
2017-11-25 23:16:29 +11:00
{% endif %}
< ul class = "ui list" >
{% for auth_method in auth_methods %}
< li > < a href = "/auth/{{ auth_method[0] }}/login" target = "_blank" onclick = "login(this);return false;" > {{ auth_method[1] }}< / a > < / li >
{% endfor %}
< / ul >
< div class = "ui hidden error message" id = "error_invalid_id" >
< i class = "close icon" > < / i >
< div class = "header" > Error< / div >
2017-12-04 14:38:27 +11:00
< p > The log in details you entered are not valid for this {{ election.kind }}. Please check your username and password and try again. If the issue persists, contact your {{ election.kind }} administrator.< / p >
2017-11-23 23:10:57 +11:00
< / div >
< div class = "ui hidden error message" id = "error_unknown" >
< i class = "close icon" > < / i >
< div class = "header" > Error< / div >
2017-12-04 14:38:27 +11:00
< p > An unknown error occurred while attempting to cast your ballot. You may click the ‘Cast ballot’ button below to try again. If the issue persists, contact your {{ election.kind }} administrator.< / p >
2017-11-23 23:10:57 +11:00
< p id = "error_unknown_tech" > < / p >
< / div >
< / div >
2018-01-08 00:01:07 +11:00
< div class = "ui basic segment" id = "casting" style = "display: none; min-height: 4em;" >
2017-11-23 23:10:57 +11:00
< div class = "ui active text loader" > Casting your ballot. Please wait.< / div >
< / div >
{% endblock %}
{% block buttons %}
2017-12-11 17:35:12 +11:00
< button class = "ui left floated button" onclick = "prevTemplate(2);" > Back< / button >
2017-11-26 20:48:15 +11:00
< button class = "ui right floated primary button" id = "cast_button" onclick = "castBallot();" { % if not username % } style = "display: none;" { % endif % } > Cast ballot< / button >
2017-11-23 23:10:57 +11:00
{% endblock %}
{% block after %}
< script >
$(".message .close").on("click", function() {
$(this).closest(".message").addClass("hidden");
});
2017-11-25 23:16:29 +11:00
function login(el) {
window.open(el.getAttribute("href"), "eos_login_window", "width=400,height=600");
}
2017-11-26 20:48:15 +11:00
function callback_complete(username) {
$("#cast_button").show();
$("#booth_logged_in_as").text("You are currently logged in as " + username + ".");
2017-11-25 23:16:29 +11:00
castBallot();
2017-11-28 14:45:54 +11:00
return true;
2017-11-25 23:16:29 +11:00
}
2017-11-23 23:10:57 +11:00
function castBallot() {
$("#cast_prompt").hide();
$("#casting").show();
2017-11-28 22:43:32 +11:00
// Prepare ballot
booth.ballot = booth.ballot.deaudit();
2017-11-23 23:10:57 +11:00
$.ajax({
url: "{{ election_base_url }}cast_ballot",
type: "POST",
data: eosjs.eos.core.objects.__all__.EosObject.to_json({
2017-12-11 13:53:25 +11:00
"ballot": eosjs.eos.core.objects.__all__.EosObject.serialise_and_wrap(booth.ballot, null),
"fingerprint": booth.fingerprint || null
2017-11-23 23:10:57 +11:00
}),
contentType: "application/json",
dataType: "text"
})
.done(function(data) {
response = eosjs.eos.core.objects.__all__.EosObject.from_json(data);
booth.voter = eosjs.eos.core.objects.__all__.EosObject.deserialise_and_unwrap(response.voter);
booth.vote = eosjs.eos.core.objects.__all__.EosObject.deserialise_and_unwrap(response.vote);
// Clear plaintexts
booth.answers = null;
nextTemplate();
})
.fail(function(xhr, status, err) {
if (xhr.status === 403) { // Forbidden
2017-11-25 23:16:29 +11:00
$("#error_invalid_id").removeClass("hidden");
2017-11-23 23:10:57 +11:00
$("#error_unknown").addClass("hidden");
} else {
2017-11-26 11:17:28 +11:00
if (xhr.responseText & & xhr.responseText.length < 100 ) {
$("#error_unknown_tech").text("Technical details: " + err + " – " + xhr.responseText);
} else {
$("#error_unknown_tech").text("Technical details: " + err);
}
2017-11-23 23:10:57 +11:00
$("#error_unknown").removeClass("hidden");
2017-11-25 23:16:29 +11:00
$("#error_invalid_id").addClass("hidden");
2017-11-23 23:10:57 +11:00
}
$("#casting").hide();
$("#cast_prompt").show();
2017-11-26 11:17:28 +11:00
console.error(xhr);
2017-11-23 23:10:57 +11:00
throw err;
});
}
< / script >
{% endblock %}