diff --git a/eos/core/objects/__init__.py b/eos/core/objects/__init__.py index 6f18e1c..396c083 100644 --- a/eos/core/objects/__init__.py +++ b/eos/core/objects/__init__.py @@ -149,7 +149,7 @@ class DateTimeField(Field): if is_python: return datetime.strptime(value, '%Y-%m-%dT%H:%M:%SZ') else: - return Date.parse(value) + return __pragma__('js', '{}', 'new Date(value)') @staticmethod def now(): diff --git a/eosweb/core/main.py b/eosweb/core/main.py index 3445211..6cf2546 100644 --- a/eosweb/core/main.py +++ b/eosweb/core/main.py @@ -96,6 +96,7 @@ def setup_test_election(): election.voters.append(Voter(name='Alice')) election.voters.append(Voter(name='Bob')) election.voters.append(Voter(name='Charlie')) + election.voters.append(Voter(name='RunasSudo')) election.mixing_trustees.append(InternalMixingTrustee(name='Eos Voting')) election.mixing_trustees.append(InternalMixingTrustee(name='Eos Voting')) @@ -172,8 +173,9 @@ def election_view(election): @using_election def election_booth(election): selection_model_view_map = EosObject.to_json({key._name: val for key, val in model_view_map.items()}) # ewww + auth_methods = EosObject.to_json(app.config['AUTH_METHODS']) - return flask.render_template('election/booth.html', election=election, selection_model_view_map=selection_model_view_map) + return flask.render_template('election/booth.html', election=election, selection_model_view_map=selection_model_view_map, auth_methods=auth_methods) @app.route('/election//view/questions') @using_election @@ -193,20 +195,24 @@ def election_view_trustees(election): @app.route('/election//cast_ballot', methods=['POST']) @using_election def election_api_cast_vote(election): - if election.workflow.get_task('eos.base.workflow.TaskOpenVoting').status >= WorkflowTask.Status.EXITED or election.workflow.get_task('eos.base.workflow.TaskCloseVoting').status <= WorkflowTask.Status.READY: + if election.workflow.get_task('eos.base.workflow.TaskOpenVoting').status < WorkflowTask.Status.EXITED or election.workflow.get_task('eos.base.workflow.TaskCloseVoting').status > WorkflowTask.Status.READY: # Voting is not yet open or has closed - return flask.Response('Voting is not yet open or has closed', 405) + return flask.Response('Voting is not yet open or has closed', 409) data = json.loads(flask.request.data) + if 'user' not in flask.session: + # User is not authenticated + return flask.Response('Not authenticated', 403) + voter = None for election_voter in election.voters: - if election_voter.name == data['auth']['username']: + if election_voter.name == flask.session['user'].username: voter = election_voter break if voter is None: - # User is not authenticated + # Invalid user return flask.Response('Invalid credentials', 403) # Cast the vote diff --git a/eosweb/core/static/nunjucks/booth/cast.html b/eosweb/core/static/nunjucks/booth/cast.html index 4709c84..c4ecc44 100644 --- a/eosweb/core/static/nunjucks/booth/cast.html +++ b/eosweb/core/static/nunjucks/booth/cast.html @@ -21,17 +21,24 @@ {% block content %}

Your vote has not yet been cast. If you have not already done so, please make a note of your ballot fingerprint, {{ eosjs.eos.core.hashing.__all__.SHA256().update_obj(ballot).hash_as_b64() }}.

-

This election requires you to log in to vote. Please enter your name below, then click ‘Cast ballot’ to cast your ballot.

-
-
- - -
-
- -
Error
-

The log in details you entered are not valid for this election. Please check your username and password and try again. If the issue persists, contact your election administrator.

-
+

This election requires you to log in to vote. If you disconnected your internet connection earlier, you must now reconnect it before proceeding.

+ + {% if username %} +

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.

+ {% else %} +

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.

+ {% endif %} + + + +