|
@@ -33,6 +33,20 @@ def main():
|
|
|
)
|
|
|
|
|
|
|
|
|
+@login_required
|
|
|
+@BLUEPRINT.route("/codes")
|
|
|
+def codes():
|
|
|
+ """codes overview"""
|
|
|
+ code = Code.query.order_by(Code.expire_date.desc()).first()
|
|
|
+ users = User.query.all()
|
|
|
+
|
|
|
+ return render_template(
|
|
|
+ 'vote/codes.j2',
|
|
|
+ users=users,
|
|
|
+ code=code,
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
@BLUEPRINT.route('/create', methods=["GET", "POST"])
|
|
|
@login_required
|
|
|
def create():
|
|
@@ -120,25 +134,23 @@ def public(ballot_id):
|
|
|
"""Vote and view results of ballot"""
|
|
|
ballot = Ballot.query.get(ballot_id)
|
|
|
|
|
|
-# code = Code()
|
|
|
-# code.secret = "test"
|
|
|
-
|
|
|
-# db.session.add(code)
|
|
|
-# db.session.commit()
|
|
|
if request.method == 'POST':
|
|
|
security_code = request.form['security_code']
|
|
|
code = Code.query.order_by(Code.expire_date.desc()).first()
|
|
|
- print(code.get_digest(code))
|
|
|
user_id = None
|
|
|
- for user in User.all():
|
|
|
- if security_code == code.get_digest(str(user.id)):
|
|
|
+ for user in User.query.all():
|
|
|
+ if security_code == code.get_digest(user.id):
|
|
|
user_id = user.id
|
|
|
|
|
|
if user_id is not None:
|
|
|
for question_id, option_id in request.form.items():
|
|
|
- if question_id == 'code':
|
|
|
+ if question_id == 'security_code':
|
|
|
continue
|
|
|
question = Question.query.get(question_id)
|
|
|
+ for option in question.options:
|
|
|
+ if option.votes.filter(Vote.user_id == user_id).first():
|
|
|
+ flash('Je hebt al gestemd.', 'warning')
|
|
|
+ return redirect(url_for('vote.public', ballot_id=ballot.id))
|
|
|
option = question.options.filter(Option.id == option_id).first()
|
|
|
|
|
|
vote = Vote()
|
|
@@ -147,9 +159,9 @@ def public(ballot_id):
|
|
|
db.session.add(vote)
|
|
|
|
|
|
db.session.commit()
|
|
|
- flash('Succesvol gestemd', 'success')
|
|
|
+ flash('Succesvol gestemd.', 'success')
|
|
|
else:
|
|
|
- flash('Fout in veiligheids code', 'warning')
|
|
|
+ flash('Fout in veiligheids code.', 'warning')
|
|
|
|
|
|
return render_template(
|
|
|
'vote/public.j2',
|