-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
203 lines (163 loc) · 5.67 KB
/
Copy pathmain.py
File metadata and controls
203 lines (163 loc) · 5.67 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
from sqlalchemy import *
from flask import Flask, render_template, redirect, url_for, flash, request
from datetime import datetime
from random import randint
import hashlib
app = Flask(__name__)
db = create_engine('sqlite:///signature.db')
db.echo = False
metadata = MetaData(db)
status_connected = False
rs = []
users = Table('users', metadata,
Column('id', Integer, primary_key=True),
Column('name', String),
Column('email', String, unique=True),
Column('password', String),
Column('img_id', Integer)
)
#users.create()
log = Table('logs', metadata,
Column('id', Integer, ForeignKey("users.id"), primary_key=True),
Column('date_time', Text, primary_key=True),
Column('whereFrom', String),
Column('accepted', Boolean),
Column('img_id', Integer)
)
#log.create()
def run(stmt):
rs = stmt.execute()
for row in rs:
return row
def renderLogData(stmt):
rs = stmt.execute()
for row in rs:
flash(row)
return
# ----- Routes -----
@app.route('/')
def index():
return render_template('index.html', status=status_connected)
@app.route('/login/')
def login_user():
return render_template('login.html')
@app.route('/register')
def register_user():
return render_template('register.html')
@app.route('/my_log')
def show_log():
global status_connected
if status_connected:
global rs
s = log.select(log.c.id == rs[0])
renderLogData(s)
return render_template('log_entry.html')
else:
return render_template('403.html')
@app.route('/home', methods=['GET', 'POST'])
def treat_login():
if request.method == 'POST':
my_email = request.form['email']
s = users.select(users.c.email == my_email)
global rs
rs = run(s)
print(rs)
if rs is None:
flash('Invalid email or password', 'error')
return redirect(url_for('login_user'))
else:
my_password = request.form['password']
encrypted_pass = hashlib.sha256(my_password).hexdigest()
if encrypted_pass == rs[3]:
global status_connected
status_connected = True
return redirect(url_for('show_log'))
else:
flash('Invalid email or password', 'error')
return redirect(url_for('login_user'))
@app.route('/registering', methods=['GET', 'POST'])
def treat_register():
if request.method == 'POST':
my_email = request.form['email']
s = users.select(users.c.email == my_email)
rs = run(s)
if rs is None:
my_password = request.form['password']
my_password2 = request.form['password2']
if my_password == my_password2:
encrypted_pass = hashlib.sha256(my_password).hexdigest()
v0 = randint(0, 3)
v1 = randint(0, 3)
v2 = randint(0, 3)
v3 = randint(0, 3)
new_signature = v0 * 1000 + v1 * 100 + v2 * 10 + v3
i = users.insert()
i.execute(name=request.form['name'], email=my_email, password=encrypted_pass, img_id=new_signature)
flash('Successfully registered, now you can Log In!', 'success'),
return render_template('login.html')
else:
flash('Your passwords do not match!', 'error')
return redirect(url_for('register_user'))
else:
flash('This email is already registered!', 'error')
return redirect(url_for('login_user'))
@app.route('/gensignature')
def add_log_entry():
z = 0
global rs
s = users.select(users.c.id == rs[0])
rs = run(s)
i = log.insert()
companies = ['Detusche Bank', 'BBVA', 'ING', 'McDonalds', 'SEUR', 'Postman Barcelona street 123']
while z < 50:
v0 = randint(0, 3)
v1 = randint(0, 3)
v2 = randint(0, 3)
v3 = randint(0, 3)
z += 1
new_signature = v0 * 1000 + v1 * 100 + v2 * 10 + v3
new_signature1 = str(new_signature)
if new_signature1 == rs[4]:
i.execute(id=rs[0], date_time=str(datetime.now()), whereFrom=companies[randint(0, 5)], accepted=True, img_id=new_signature)
return redirect(url_for('show_log'))
i.execute(id=rs[0], date_time=str(datetime.now()), whereFrom=companies[randint(0, 5)], accepted=False, img_id=new_signature)
return redirect(url_for('show_log'))
@app.route('/showsimulation', methods=['GET', 'POST'])
def showSignature():
global rs
# My signature
ourselection = int(rs[4])
myv0 = ourselection / 1000
myv1 = (ourselection % 1000) / 100
myv2 = (ourselection % 100) / 10
myv3 = ourselection % 10
# DB signature
selected_image = int(request.form['dataCross'])
logv0 = selected_image / 1000
logv1 = (selected_image % 1000) / 100
logv2 = (selected_image % 100) / 10
logv3 = selected_image % 10
return render_template('splines.html', myv0=myv0, myv1=myv1, myv2=myv2, myv3=myv3, logv0=logv0, logv1=logv1, logv2=logv2, logv3=logv3)
@app.route('/backanimation')
def wheretoback():
if status_connected:
return redirect(url_for('show_log'))
else:
return redirect(url_for('login_user'))
@app.route('/logout')
def logout():
global status_connected
status_connected = False
return redirect(url_for('index'))
@app.errorhandler(403)
def page_forbidden(e):
return render_template('403.html'), 403
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
@app.errorhandler(IndexError)
def internal_error(e):
return render_template('403.html')
if __name__ == "__main__":
app.secret_key = '1234'
app.run(debug=True)