-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
index.py
132 lines (114 loc) · 4.42 KB
/
index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Copyright Fortior Blockchain, LLLP 2021
# Open Source under Apache License
from flask import Flask, request, render_template, redirect, url_for
from algosdk import account, encoding, mnemonic
from vote import election_voting, hashing, corporate_voting, count_votes, count_corporate_votes
from vote import reset_votes, reset_corporate_votes
from algosdk.future.transaction import AssetTransferTxn, PaymentTxn
from algosdk.v2client import algod
import rsa
import hashlib
import sqlite3 as sl
# Added new sqlite functionality for local devices
con = sl.connect('voters.db', check_same_thread=False)
cur = con.cursor()
app = Flask(__name__, template_folder="templates", static_folder="static")
finished = False
corporate_finished = False
validated = False
a = '04f3b7d69eb1b993c97d3789685c5e3fc034d5dbad2bd634e34ca287673d0381a1935afc9ac7f6c9e4dee7631f771be445c2543e96189070c50d571fec16281d'
dd = 'oluwatunmise'
@app.route("/")
def start():
""" Start page """
return render_template('index.html')
@app.route('/start', methods=['POST', 'GET'])
def start_voting():
error = ''
message = ''
global finished
if request.method == 'POST':
key = hashing(str(request.form.get('Key')))
# if key == '09a1d01b5b120d321de9529369640316ddb120870df1ec03b3f2c6dd39c1ff6ecf8de5e56eb32d79c9d06240eaf5de027f6e7b9df2e2e1a4cb38dd548460b757':
if key == a:
# message = reset_votes()
finished = False
else:
error = "Incorrect admin key"
return render_template("start.html", message=message, error=error)
@app.route('/create', methods=['POST', 'GET'])
def create():
message = ''
error = ''
if request.method == 'POST':
Social = hashing(str(request.form.get('Social')))
Drivers = hashing(str(request.form.get('Drivers')))
Key = hashing(str(request.form.get('Key')))
# if str(Key) == '09a1d01b5b120d321de9529369640316ddb120870df1ec03b3f2c6dd39c1ff6ecf8de5e56eb32d79c9d06240eaf5de027f6e7b9df2e2e1a4cb38dd548460b757':
if str(Key) == a:
cur.execute("INSERT INTO USER (DL, SS) VALUES(?,?)", ((Drivers, Social)))
con.commit()
else:
error = 'Incorrect admin key'
return render_template('create.html', message=message, error=error)
@app.route('/end', methods=['POST', 'GET'])
def end():
error = ''
message = ''
global finished
if request.method == 'POST':
key = hashing(str(request.form.get('Key')))
# if key == '09a1d01b5b120d321de9529369640316ddb120870df1ec03b3f2c6dd39c1ff6ecf8de5e56eb32d79c9d06240eaf5de027f6e7b9df2e2e1a4cb38dd548460b757':
if key == a:
message = count_votes()
finished = True
else:
error = "Incorrect admin key"
return render_template("end.html", message=message, error=error)
@app.route('/vote', methods=['POST', 'GET'])
def vote():
error = ''
message = ''
global validated
validated = False
if request.method == 'POST':
Social = hashing(str(request.form.get('Social')))
Drivers = hashing(str(request.form.get('Drivers')))
cur.execute("SELECT * FROM USER WHERE SS = ? AND DL = ?", (Social, Drivers))
account = cur.fetchone()
if account:
cur.execute("DELETE FROM USER WHERE SS = ? and DL = ?", (Social, Drivers))
con.commit()
validated = True
return redirect(url_for('submit'))
else:
error = 'Your info is incorrect'
elif finished == True:
message = count_votes()
return render_template("end.html", message=message, error=error)
return render_template('vote.html', message=message, error=error)
@app.route('/submit', methods=['POST', 'GET'])
def submit():
error = ''
message = ''
global validated
if not validated:
return redirect(url_for('vote'))
else:
if request.method == 'POST':
vote = request.values.get("options")
if vote == 'option1':
vote = "YES"
message = election_voting(vote)
elif vote == 'option2':
vote = "NO"
message = election_voting(vote)
else:
error = "You did not enter a vote"
return render_template('submit.html', message=message, error=error)
@app.route('/about/')
def about():
"""about"""
return render_template('about.html')
if __name__ == "__main__":
app.run(host='127.0.0.1', debug=True)