-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
190 lines (138 loc) · 5.22 KB
/
app.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
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
import json
from flask import Flask, render_template, jsonify, request, redirect, session, flash
from static.database import *
app = Flask(__name__)
app.secret_key = 'super secret key'
@app.route('/')
def welcome_page(): # put application's code here
return render_template('index.html')
@app.route('/magasin')
def magasin():
types_billets = list(selectionner_types_billets())
return render_template('magasin.html', types_billets=types_billets)
@app.route('/magasin/<tbid>')
def details_billets(tbid):
type_billet = select_type_billet_par_id(tbid)
spectacles = selectionner_spectacles()
return render_template('details-billet.html', type_billet=type_billet, spectacles=spectacles)
@app.route('/panier')
def panier():
return render_template('panier.html')
@app.route('/deconnexion')
def deconnexion():
session.clear()
return render_template('index.html')
@app.route('/programmation')
def programmation():
artistes = selectionner_programmation()
# Print the number and content of artistes
print("Number of artists:", len(artistes))
print("Artists:", artistes)
return render_template('programmation.html', artistes=artistes)
@app.get('/types-billets')
def req_types_billets():
return selectionner_types_billets()
@app.route('/confirmation-achat')
def afficher_confirmation_commande():
id_commande = request.args.get('id_commande')
commande = selectionner_commande_par_id(id_commande)
return render_template('confirmation-commande.html', commande=commande)
@app.route('/scanner-billet')
def scanner_billet():
return render_template('scanner-billet.html', spectacles=selectionner_spectacles())
@app.get('/item-panier')
def req_item_panier():
tbid = request.args.get('tbid')
sid = request.args.get('sid')
if sid:
res = selectionner_item_panier(tbid, sid)
else:
res = select_type_billet_par_id(tbid)
reponse = {
"status": 200,
"body": res
}
return jsonify(reponse)
@app.context_processor
def injecter_menu():
return {'menu': 'menu.html'}
# TODO ajouter route pour créer un compte (4)
# TODO ajouter route pour se connecter
# NOT TODO ajouter route pour valider un billet à l'entrée (2)
# NOT TODO ajouter routes pour faire gestion des spectacles (ajouter description, associer les artistes aux scène(procedure faite))
@app.post('/commander')
def creer_commande():
# try:
json_data = request.data.decode('utf-8')
id_commande = commander_billets(json_data, session['user_id'])
reponse = {
"status": 200,
"body": id_commande
}
return jsonify(reponse)
@app.post('/valider-billet')
def valider_billet():
args = dict(json.loads(request.data.decode('utf-8')))
resultat = verifier_acces(args.get('id_billet'), args.get('id_spectacle'))
reponse = {
"status": 200 if resultat else 400,
"body": resultat
}
return jsonify(reponse)
# except Exception as e:
# print(e)
# return 'Une erreur s\'est produit veuillez réessayer plus tard.', 400
@app.route('/creation_compte', methods=['GET', 'POST'])
def inscription():
if request.method == 'POST':
connection = pool.get_connection()
nom = request.form['nom']
mot_de_passe = request.form['mot_de_passe']
telephone = request.form['telephone']
date_naissance = request.form['date_naissance']
courriel = request.form['courriel']
cursor = connection.cursor()
# Validate user input
if not check_user_email(courriel):
flash('courriel invalide', 'error')
return redirect(request.url)
if not check_user_telephone(telephone):
flash('numéro de téléphone invalide', 'error')
return redirect(request.url)
if not check_user_date(date_naissance):
flash('date de naissance invalide', 'error')
return redirect(request.url)
# If validation passes, insert user into the database
insert_user(nom, mot_de_passe, telephone, date_naissance, courriel)
connection.commit()
cursor.close()
return redirect('/connexion')
if request.method == 'GET':
return render_template('creation-compte.html')
@app.route('/connexion', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
email = request.form['email']
password = request.form['password']
print(f"Password from form: {password}") # Debugging line
try:
if check_user_password(email, password):
# Authentication successful
user = get_user(email)
session['logged_in'] = True
session['email'] = email
session['user_id'] = user['uid']
session['nom'] = user['nom']
session['is_admin'] = True if user['est_admin'] == 1 else False
return redirect('/')
else:
# Authentication failed
return "Email ou mot de passe incorrect"
except ValueError as e:
return str(e)
if request.method == 'GET':
return render_template('connexion.html')
def verifier_paiement():
return True
if __name__ == '__main__':
app.run(port=8000, debug=True)