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
|
@app.route("/")
@app.route("/index")
def index():
if not session.get('logged_in'):
return render_template('login.html')
else:
if app.NOM == '':
return render_template('login.html', login=1)
else:
var = "SELECT users.prenom, users.nom, data.bpm, data.oxy, data.chute FROM data, users WHERE users.ID = '" + str(app.ID) + "' AND data.User = '" + str(app.ID) + "' ORDER BY data.User DESC LIMIT 1 "
try:
cur = bdd_login()
except pymysql.Error as e:
return session_out(e)
result = cur.execute(var)
cur.close()
print(result)
if not result:
bpm = 0
oxy = 0
chute = 0
else:
for row in cur:
print(row)
bpm = row[2]
oxy = row[3]
chute = row[4]
templateData = {'prenom': app.PRENOM, 'nom': app.NOM, 'rank': app.RANK, 'bpm': bpm, 'oxy': oxy, 'town': app.TOWN}
if bpm < 40 or bpm > 100:
if oxy < 80:
if chute == 0:
return render_template('index.html', **templateData, state_bpm=0, state_oxy=0, state_chute=0)
else:
return render_template('index.html', **templateData, state_bpm=0, state_oxy=0, state_chute=1)
elif 95 <= oxy <= 100:
if chute == 0:
return render_template('index.html', **templateData, state_bpm=0, state_oxy=1, state_chute=0)
else:
return render_template('index.html', **templateData, state_bpm=0, state_oxy=1, state_chute=1)
elif 80 <= oxy < 95:
if chute == 0:
return render_template('index.html', **templateData, state_bpm=0, state_oxy=2, state_chute=0)
else:
return render_template('index.html', **templateData, state_bpm=0, state_oxy=2, state_chute=1)
elif 60 <= bpm <= 80:
if oxy < 80:
if chute == 0:
return render_template('index.html', **templateData, state_bpm=1, state_oxy=0, state_chute=0)
else:
return render_template('index.html', **templateData, state_bpm=1, state_oxy=0, state_chute=1)
elif 95 <= oxy <= 100:
if chute == 0:
return render_template('index.html', **templateData, state_bpm=1, state_oxy=1, state_chute=0)
else:
return render_template('index.html', **templateData, state_bpm=1, state_oxy=1, state_chute=1)
elif 80 <= oxy < 95:
if chute == 0:
return render_template('index.html', **templateData, state_bpm=1, state_oxy=2, state_chute=0)
else:
return render_template('index.html', **templateData, state_bpm=1, state_oxy=2, state_chute=1)
elif 40 <= bpm < 60 or 80 < bpm <= 100:
if oxy < 80:
if chute == 0:
return render_template('index.html', **templateData, state_bpm=2, state_oxy=0, state_chute=0)
else:
return render_template('index.html', **templateData, state_bpm=2, state_oxy=0, state_chute=1)
elif 95 <= oxy <= 100:
if chute == 0:
return render_template('index.html', **templateData, state_bpm=2, state_oxy=1, state_chute=0)
else:
return render_template('index.html', **templateData, state_bpm=2, state_oxy=1, state_chute=1)
elif 80 <= oxy < 95:
if chute == 0:
return render_template('index.html', **templateData, state_bpm=2, state_oxy=2, state_chute=0)
else:
return render_template('index.html', **templateData, state_bpm=2, state_oxy=2, state_chute=1)
@app.route("/login", methods=['POST'])
def login():
POST_NAME = str(request.form['nom'])
POST_PRENOM = str(request.form['prenom'])
POST_PASSWORD = str(request.form['password'])
var = "SELECT id, nom, prenom, password, privilege FROM users WHERE nom = '" + POST_NAME + "' AND password = '" + POST_PASSWORD + "' AND prenom = '" + POST_PRENOM + "'"
try:
cur = bdd_login()
except pymysql.Error as e:
return session_out(e)
result = cur.execute(var)
cur.close()
for row in cur:
print(row)
if result:
session.permanent = True
session['logged_in'] = True
session['prenom'] = POST_PRENOM
session['nom'] = POST_NAME
session['ID'] = row[0]
if row[4] == 'patient':
session['rank'] = 0
if row[4] == 'proche':
session['rank'] = 1
if row[4] == 'med':
session['rank'] = 2
if row[4] == 'admin':
session['rank'] = 3
app.NOM = session['nom']
app.PRENOM = session['prenom']
app.RANK = session['rank']
app.ID = session['ID']
templateData = {'prenom': app.PRENOM, 'nom': app.NOM, 'rank': app.RANK}
print('coucou')
return render_template('index.html', **templateData)
else:
return render_template('login.html', login=0)
@app.route("/logout")
def logout():
session['logged_in'] = False
session.pop('prenom', None)
session.pop('nom', None)
session.pop('ID', None)
session.pop('rank', None)
app.PRENOM = ""
app.NOM = ""
app.RANK = ""
app.ID = ""
app.TOWN = ""
return index() |
Partager