Implement voters in terms of users
This commit is contained in:
parent
7ea360b5d4
commit
f31f5347e2
@ -38,6 +38,7 @@ for f in eos.js_tests; do
|
||||
|
||||
# Transcrypt bug
|
||||
perl -0777 -pi -e 's/property.call \((.*?), \g1.\g1.__impl__(.*?)\)/property.call ($1, $1.__impl__$2)/g' eos/__javascript__/$f.js
|
||||
perl -0777 -pi -e 's/property.call \((.*?), \g1.\g1.__implpy_(.*?)\)/property.call ($1, $1.__impl__$2)/g' eos/__javascript__/$f.js
|
||||
done
|
||||
|
||||
cp eos/__javascript__/eos.js_tests.js eosweb/core/static/js/eosjs.js
|
||||
|
@ -41,11 +41,17 @@ class Vote(EmbeddedObject):
|
||||
|
||||
class Voter(EmbeddedObject):
|
||||
_id = UUIDField()
|
||||
name = StringField()
|
||||
votes = EmbeddedObjectListField()
|
||||
|
||||
class EmailVoter(Voter):
|
||||
email = StringField()
|
||||
class User(EmbeddedObject):
|
||||
pass
|
||||
|
||||
class UserVoter(Voter):
|
||||
user = EmbeddedObjectField()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self.user.name
|
||||
|
||||
class Question(EmbeddedObject):
|
||||
prompt = StringField()
|
||||
|
@ -26,3 +26,5 @@ import eos.psr.crypto
|
||||
import eos.psr.election
|
||||
import eos.psr.mixnet
|
||||
import eos.psr.workflow
|
||||
|
||||
import eos.redditauth.election
|
||||
|
0
eos/redditauth/__init__.py
Normal file
0
eos/redditauth/__init__.py
Normal file
31
eos/redditauth/election.py
Normal file
31
eos/redditauth/election.py
Normal file
@ -0,0 +1,31 @@
|
||||
# Eos - Verifiable elections
|
||||
# Copyright © 2017 RunasSudo (Yingtong Li)
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
from eos.base.election import *
|
||||
from eos.core.objects import *
|
||||
|
||||
class RedditUser(User):
|
||||
oauth_token = StringField(is_protected=True)
|
||||
username = StringField()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self.username
|
||||
|
||||
def matched_by(self, other):
|
||||
if not isinstance(other, RedditUser):
|
||||
return False
|
||||
return other.username == self.username
|
@ -92,11 +92,8 @@ def setup_test_election():
|
||||
# Set election details
|
||||
election.name = 'Test Election'
|
||||
|
||||
voter = Voter()
|
||||
election.voters.append(Voter(name='Alice'))
|
||||
election.voters.append(Voter(name='Bob'))
|
||||
election.voters.append(Voter(name='Charlie'))
|
||||
election.voters.append(Voter(name='RunasSudo'))
|
||||
from eos.redditauth.election import RedditUser
|
||||
election.voters.append(UserVoter(user=RedditUser(username='RunasSudo')))
|
||||
|
||||
election.mixing_trustees.append(InternalMixingTrustee(name='Eos Voting'))
|
||||
election.mixing_trustees.append(InternalMixingTrustee(name='Eos Voting'))
|
||||
@ -207,7 +204,7 @@ def election_api_cast_vote(election):
|
||||
|
||||
voter = None
|
||||
for election_voter in election.voters:
|
||||
if election_voter.name == flask.session['user'].username:
|
||||
if election_voter.user.matched_by(flask.session['user']):
|
||||
voter = election_voter
|
||||
break
|
||||
|
||||
@ -223,8 +220,8 @@ def election_api_cast_vote(election):
|
||||
election.save()
|
||||
|
||||
return flask.Response(json.dumps({
|
||||
'voter': EosObject.serialise_and_wrap(voter),
|
||||
'vote': EosObject.serialise_and_wrap(vote)
|
||||
'voter': EosObject.serialise_and_wrap(voter, should_protect=True),
|
||||
'vote': EosObject.serialise_and_wrap(vote, should_protect=True)
|
||||
}), mimetype='application/json')
|
||||
|
||||
@app.route('/debug')
|
||||
|
@ -24,9 +24,9 @@
|
||||
<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 %}
|
||||
<p>You are currently logged in as {{ username }}. Please select an option from the list below if you would like to switch accounts. Otherwise, click ‘Cast ballot’ to continue.</p>
|
||||
<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>
|
||||
{% else %}
|
||||
<p>You are not currently logged in. Please select an option from the list below to log in. Your ballot will be automatically cast once you have logged in.</p>
|
||||
<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>
|
||||
{% endif %}
|
||||
|
||||
<ul class="ui list">
|
||||
@ -69,6 +69,7 @@
|
||||
}
|
||||
function callback_complete() {
|
||||
$("#cast_button").removeClass("hidden");
|
||||
$("#booth_logged_in_as").text("You are currently logged in.");
|
||||
castBallot();
|
||||
}
|
||||
|
||||
@ -101,7 +102,11 @@
|
||||
|
||||
$("#error_unknown").addClass("hidden");
|
||||
} else {
|
||||
$("#error_unknown_tech").text("Technical details: " + err + " – " + xhr.responseText);
|
||||
if (xhr.responseText && xhr.responseText.length < 100) {
|
||||
$("#error_unknown_tech").text("Technical details: " + err + " – " + xhr.responseText);
|
||||
} else {
|
||||
$("#error_unknown_tech").text("Technical details: " + err);
|
||||
}
|
||||
$("#error_unknown").removeClass("hidden");
|
||||
|
||||
$("#error_invalid_id").addClass("hidden");
|
||||
@ -110,6 +115,7 @@
|
||||
$("#casting").hide();
|
||||
$("#cast_prompt").show();
|
||||
|
||||
console.error(xhr);
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
|
33
eosweb/core/templates/auth/login_cancelled.html
Normal file
33
eosweb/core/templates/auth/login_cancelled.html
Normal file
@ -0,0 +1,33 @@
|
||||
{% extends 'semantic_base.html' %}
|
||||
|
||||
{#
|
||||
Eos - Verifiable elections
|
||||
Copyright © 2017 RunasSudo (Yingtong Li)
|
||||
|
||||
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 title %}Login{% endblock %}
|
||||
|
||||
{% block basecontent %}
|
||||
<div class="ui middle aligned center aligned grid" style="height: 100%;">
|
||||
<div class="column" style="max-width: 400px;">
|
||||
<div class="ui error message">
|
||||
<div class="header">Log in cancelled</div>
|
||||
<p>You have cancelled the request to log in to your account.</p>
|
||||
<p>If you do wish to log in to your account, please close this window and try again.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
@ -18,15 +18,11 @@ from flask_oauthlib.client import OAuth
|
||||
|
||||
import flask
|
||||
|
||||
from eos.core.objects import *
|
||||
from eos.redditauth.election import *
|
||||
|
||||
import base64
|
||||
import uuid
|
||||
|
||||
class RedditUser(DocumentObject):
|
||||
oauth_token = StringField(is_protected=True)
|
||||
username = StringField()
|
||||
|
||||
def main(app):
|
||||
oauth = OAuth()
|
||||
reddit = oauth.remote_app('Reddit',
|
||||
|
Loading…
Reference in New Issue
Block a user