first commit
This commit is contained in:
BIN
TP_Flask_petit_serveur_web_NSI.pdf
Normal file
BIN
TP_Flask_petit_serveur_web_NSI.pdf
Normal file
Binary file not shown.
BIN
__pycache__/repertoire_identifiants_mot_de_passe.cpython-311.pyc
Normal file
BIN
__pycache__/repertoire_identifiants_mot_de_passe.cpython-311.pyc
Normal file
Binary file not shown.
BIN
__pycache__/repertoire_identifiants_mot_de_passe.cpython-37.pyc
Normal file
BIN
__pycache__/repertoire_identifiants_mot_de_passe.cpython-37.pyc
Normal file
Binary file not shown.
BIN
__pycache__/repertoire_web.cpython-311.pyc
Normal file
BIN
__pycache__/repertoire_web.cpython-311.pyc
Normal file
Binary file not shown.
BIN
__pycache__/repertoire_web.cpython-37.pyc
Normal file
BIN
__pycache__/repertoire_web.cpython-37.pyc
Normal file
Binary file not shown.
86
app.py
Normal file
86
app.py
Normal file
@@ -0,0 +1,86 @@
|
||||
from flask import Flask, render_template, request
|
||||
from datetime import datetime
|
||||
from repertoire_web import ajouter, rechercher
|
||||
from repertoire_identifiants_mot_de_passe import verif_user, add_user
|
||||
|
||||
app = Flask(__name__) # crée l'application Flask
|
||||
|
||||
@app.route("/") # URL racine : http://localhost:5000/
|
||||
def index():
|
||||
return render_template("user_search.html",display = "none")
|
||||
|
||||
@app.route("/cherche")
|
||||
def cherche():
|
||||
return render_template("cherche.html")
|
||||
|
||||
@app.route("/form_add_user")
|
||||
def form_add_user():
|
||||
return render_template("add_user.html")
|
||||
|
||||
@app.route("/result_add_user", methods=["POST"])
|
||||
def result_add_user():
|
||||
Identifiant = request.form.get("Identifiant", "").strip()
|
||||
Mot_de_passe = request.form.get("Mot_de_passe", "").strip()
|
||||
add_user(Identifiant, Mot_de_passe)
|
||||
# return render_template("result_add_user.html", Identifiant=Identifiant, Mot_de_passe=Mot_de_passe)
|
||||
|
||||
@app.route("/ajout")
|
||||
def ajout():
|
||||
return render_template("ajout.html")
|
||||
|
||||
# Traitement des formulaires
|
||||
@app.route("/resultat_recherche", methods=["POST"])
|
||||
def resultat_recherche():
|
||||
nom = request.form.get("nom", "").strip()
|
||||
numero = rechercher(nom)
|
||||
return render_template("resultat_recherche.html", nom=nom, numero=numero)
|
||||
|
||||
@app.route("/resultat_ajout", methods=["POST"])
|
||||
def resultat_ajout():
|
||||
nom = request.form.get("nom", "").strip()
|
||||
numero = request.form.get("numero", "").strip()
|
||||
ajouter(nom, numero)
|
||||
return render_template("resultat_ajout.html", nom=nom, numero=numero)
|
||||
|
||||
@app.route("/user_search")
|
||||
def user_search():
|
||||
return render_template("user_search.html",display = "none")
|
||||
|
||||
@app.route("/result_search", methods=["POST"])
|
||||
def result_search():
|
||||
Identifiant = request.form.get("Identifiant", "").strip()
|
||||
Mot_de_passe = request.form.get("Mot_de_passe", "").strip()
|
||||
print([Identifiant,Mot_de_passe])
|
||||
if verif_user(Identifiant, Mot_de_passe):
|
||||
return render_template("index.html", Identifiant=Identifiant)
|
||||
else:
|
||||
return render_template("user_search.html", display="visible")
|
||||
|
||||
@app.route("/NOTES")
|
||||
def NOTES():
|
||||
return render_template("NOTES.html")
|
||||
|
||||
@app.route("/heure")
|
||||
def heure():
|
||||
maintenant = datetime.now()
|
||||
return render_template(
|
||||
"heure.html",
|
||||
h=maintenant.hour,
|
||||
m=maintenant.minute,
|
||||
s=maintenant.second
|
||||
)
|
||||
|
||||
@app.route("/formulaire")
|
||||
def formulaire():
|
||||
return render_template("formulaire.html")
|
||||
|
||||
@app.route("/resultat", methods=["POST"])
|
||||
def resultat():
|
||||
nom = request.form.get("nom", "").strip()
|
||||
prenom = request.form.get("prenom", "").strip()
|
||||
return render_template("resultat.html", nom=nom, prenom=prenom)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run() # lance le serveur (localhost:5000 par défaut)
|
||||
|
||||
|
||||
10
mots_de_passe_identifiants.txt
Normal file
10
mots_de_passe_identifiants.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
zebi;;prout
|
||||
zebi;;prout
|
||||
zebi;;prout
|
||||
zebi;;prout
|
||||
zebi;;2
|
||||
zebi;;prout
|
||||
zebi;;prout
|
||||
zebi;;2
|
||||
a;;a
|
||||
user;;password
|
||||
18
repertoire_identifiants_mot_de_passe.py
Normal file
18
repertoire_identifiants_mot_de_passe.py
Normal file
@@ -0,0 +1,18 @@
|
||||
_repertoire_identifiants_mot_de_passe= {
|
||||
"Alban": "mot_de_passe",
|
||||
}
|
||||
|
||||
def verif_user(Identifiant: str, Mot_de_passe: str) -> bool:
|
||||
#
|
||||
if _repertoire_identifiants_mot_de_passe.get(Identifiant, "Inconnu") == Mot_de_passe:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def add_user(Identifiant: str, Mot_de_passe: str) -> None:
|
||||
"""Ajoute ou remplace une entrée du répertoire."""
|
||||
with open('mots_de_passe_identifiants.txt','a') as f :
|
||||
f.write(Identifiant)
|
||||
f.write(';;')
|
||||
f.write(Mot_de_passe)
|
||||
f.write("\n")
|
||||
14
repertoire_web.py
Normal file
14
repertoire_web.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# Créé par alban.beltran, le 16/02/2026 en Python 3.7
|
||||
# repertoire_web.py
|
||||
_repertoire = {
|
||||
"Alice": "0600000001",
|
||||
"Bob": "0600000002"
|
||||
}
|
||||
|
||||
def rechercher(nom: str) -> str:
|
||||
"""Renvoie le numéro si le nom existe, sinon 'Inconnu'."""
|
||||
return _repertoire.get(nom, "Inconnu")
|
||||
|
||||
def ajouter(nom: str, numero: str) -> None:
|
||||
"""Ajoute ou remplace une entrée du répertoire."""
|
||||
_repertoire[nom] = numero
|
||||
BIN
static/img/TSB_logo.jpg
Normal file
BIN
static/img/TSB_logo.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 82 KiB |
BIN
static/img/logo.jpg
Normal file
BIN
static/img/logo.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.9 KiB |
BIN
static/img/rivals_logo.jpg
Normal file
BIN
static/img/rivals_logo.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 48 KiB |
33
static/style.css
Normal file
33
static/style.css
Normal file
@@ -0,0 +1,33 @@
|
||||
.playwrite-cu-guides-regular {
|
||||
font-family: "Playwrite CU Guides", cursive;
|
||||
font-weight: 400;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
|
||||
.logo-style{
|
||||
border: solid 0px black;
|
||||
background: silver;
|
||||
text-align: center;
|
||||
height: 94px;
|
||||
width: 100px;}
|
||||
body {
|
||||
font-family: "Playwrite CU Guides", cursive;
|
||||
background-color: #E9FAFC;}
|
||||
h1 {
|
||||
text-decoration: underline;
|
||||
color: red;}
|
||||
|
||||
h2 {
|
||||
text-decoration: underline;}
|
||||
|
||||
p {
|
||||
color: blue;}
|
||||
|
||||
table {
|
||||
border-collapse: separate;}
|
||||
|
||||
td {
|
||||
border-style: inset;
|
||||
border-color: #0000FF #00FFFF #00FFFF #0000FF;}
|
||||
|
||||
46
templates/NOTES.html
Normal file
46
templates/NOTES.html
Normal file
@@ -0,0 +1,46 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
||||
<title>NOTES</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>NOTES</h1>
|
||||
<h2>Jeux favoris</h2>
|
||||
<p>#1.RIVALS</p>
|
||||
<img src="{{ url_for('static', filename='img/rivals_logo.jpg') }}" alt="Logo Rivals" width="200">
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><p>favorite main weapon: SNIPER</p></td>
|
||||
<td><p>favorite secondary: daggers</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><p>favorite mele: schyte/katana</p></td>
|
||||
<td><p>favorite utility: war horn/satchels</p></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h2>#2.The Strongest Battlegrounds</h2>
|
||||
<img src="{{ url_for('static', filename='img/tSB_logo.jpg') }}" alt="Logo TSB" width="200">
|
||||
<h2>Phonk favoris</h2>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><p><a href="https://youtu.be/orOgilmiL_4">NO BATIDÃO</a></p></td>
|
||||
<td><p><a href="https://youtu.be/i_J7LVVcyoQ">MENTE MÁ</a></p></td>
|
||||
<td><p><a href="https://youtu.be/P8jJr2dN1pk">AL NACER</a></p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><p><a href="https://youtu.be/G8mfQ9rXiM4">PASSO BEM SOLTO</a></p></td>
|
||||
<td><p><a href="https://youtu.be/sLWcq3FKNEc">MONTAGEM RUGADA</a></p></td>
|
||||
<td><p><a href="https://youtu.be/UJF6ydJ2W34">MATADORA</a></p></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p><a href="{{ url_for('index') }}">Retour à l'accueil</a></p>
|
||||
<p><a href="{{ url_for('heure') }}">Verifier l'heure</a></p>
|
||||
<p><a href="{{ url_for('formulaire') }}">Aller au formulaire</a></p>
|
||||
</body>
|
||||
</html>
|
||||
17
templates/add_user.html
Normal file
17
templates/add_user.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Add_user</title>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Ajouter un utilisateur</h1>
|
||||
<form action="{{ url_for('result_add_user') }}" method="post">
|
||||
<label>Identifiant : <input name="Identifiant" required></label><br>
|
||||
<label>Mot_de_passe : <input name="Mot_de_passe" required></label><br>
|
||||
<button type="submit">Ajouter</button>
|
||||
</form>
|
||||
<p><a href="{{ url_for('index') }}">Retour</a></p>
|
||||
</body>
|
||||
</html>
|
||||
17
templates/ajout.html
Normal file
17
templates/ajout.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Ajout</title>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Ajouter</h1>
|
||||
<form action="{{ url_for('resultat_ajout') }}" method="post">
|
||||
<label>Nom : <input name="nom" required></label><br>
|
||||
<label>Numéro : <input name="numero" required></label><br>
|
||||
<button type="submit">Ajouter</button>
|
||||
</form>
|
||||
<p><a href="{{ url_for('index') }}">Retour</a></p>
|
||||
</body>
|
||||
</html>
|
||||
16
templates/cherche.html
Normal file
16
templates/cherche.html
Normal file
@@ -0,0 +1,16 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Recherche</title>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Rechercher</h1>
|
||||
<form action="{{ url_for('resultat_recherche') }}" method="post">
|
||||
<label>Nom : <input name="nom" required></label>
|
||||
<button type="submit">Chercher</button>
|
||||
</form>
|
||||
<p><a href="{{ url_for('index') }}">Retour</a></p>
|
||||
</body>
|
||||
</html>
|
||||
17
templates/formulaire.html
Normal file
17
templates/formulaire.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Formulaire</title>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Formulaire</h1>
|
||||
<form action="{{ url_for('resultat') }}" method="post">
|
||||
<label>Nom : <input type="text" name="nom" required></label><br>
|
||||
<label>Prénom : <input type="text" name="prenom" required></label><br>
|
||||
<button type="submit">Envoyer</button>
|
||||
</form>
|
||||
<p><a href="{{ url_for('index') }}">Retour</a></p>
|
||||
</body>
|
||||
</html>
|
||||
13
templates/heure.html
Normal file
13
templates/heure.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Heure</title>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Page dynamique</h1>
|
||||
<p>Il est {{ h }} h {{ m }} min {{ s }} s</p>
|
||||
<p><a href="{{ url_for('index') }}">Retour</a></p>
|
||||
</body>
|
||||
</html>
|
||||
28
templates/index.html
Normal file
28
templates/index.html
Normal file
@@ -0,0 +1,28 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<img src="{{ url_for('static', filename='img/logo.jpg') }}" alt="Logo" width="160">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
||||
<meta charset="utf-8">
|
||||
<title>Accueil</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Mon site journal</h1>
|
||||
<h2>Accueil</h2>
|
||||
<p><a href="{{ url_for('NOTES') }}">Aller sur NOTES</a></p>
|
||||
<p><a href="{{ url_for('heure') }}">Verifier l'heure</a></p>
|
||||
<p><a href="{{ url_for('formulaire') }}">Aller au formulaire</a></p>
|
||||
<h3>Répertoire</h3>
|
||||
<ul>
|
||||
<li><a href="{{ url_for('cherche') }}">Rechercher un numéro</a></li>
|
||||
<li><a href="{{ url_for('ajout') }}">Ajouter un contact</a></li>
|
||||
</ul>
|
||||
<h1>Ajouter un utilisateur</h1>
|
||||
<form action="{{ url_for('result_add_user') }}" method="post">
|
||||
<label>Identifiant : <input name="Identifiant" required></label><br>
|
||||
<label>Mot_de_passe : <input name="Mot_de_passe" required></label><br>
|
||||
<button type="submit">Ajouter</button>
|
||||
</form>
|
||||
<p><a href="{{ url_for('user_search') }}">Se connecter avec un autre identifiant</a></p>
|
||||
</body>
|
||||
</html>
|
||||
13
templates/page2.html
Normal file
13
templates/page2.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>NOTES</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>NOTES</h1>
|
||||
<p><a href="{{ url_for('index') }}">Retour à l'accueil</a></p>
|
||||
<p><a href="{{ url_for('heure') }}">Verifier l'heure</a></p>
|
||||
<p><a href="{{ url_for('formulaire') }}">Aller au formulaire</a></p>
|
||||
</body>
|
||||
</html>
|
||||
19
templates/page_hopper.html
Normal file
19
templates/page_hopper.html
Normal file
@@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang = "fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
|
||||
<title> Site informaticiens </title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>
|
||||
Grace Hopper
|
||||
</h1>
|
||||
|
||||
<img src= "images/photo_informaticiens/hopper_grace.jpg" alt="Hopper">
|
||||
|
||||
<br>
|
||||
|
||||
<a href="index.html">Retour à l'accueuil </a>
|
||||
</body>
|
||||
</html>
|
||||
17
templates/page_vide.html
Normal file
17
templates/page_vide.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="style/style_base.css" />
|
||||
<title> Mon Titre</title>
|
||||
<style type="text/css">
|
||||
h1:hover {color: green;}
|
||||
p {text-align: center;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1 style="color: blueviolet;">Ma page web</h1>
|
||||
|
||||
<p > Mon pargraphe </p>
|
||||
</body>
|
||||
</html>
|
||||
11
templates/result_add_user.html
Normal file
11
templates/result_add_user.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head><meta charset="utf-8"><title>Utilisateur ajouté</title></head>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
||||
<body>
|
||||
<h1>L'utilisateur {{Identifiant}} à été ajouté</h1>
|
||||
<p><a href="{{ url_for('index') }}">Retour accueil</a></p>
|
||||
<p><a href="{{ url_for('add_user') }}">ajouter un autre utilisateur</a></p>
|
||||
<p><a href="{{ url_for('user_search') }}">Se connecter avec un autre identifiant</a></p>
|
||||
</body>
|
||||
</html>
|
||||
12
templates/resultat.html
Normal file
12
templates/resultat.html
Normal file
@@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Résultat</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Résultat</h1>
|
||||
<p>Bonjour {{ prenom }} {{ nom }} !</p>
|
||||
<p><a href="{{ url_for('formulaire') }}">Revenir au formulaire</a></p>
|
||||
</body>
|
||||
</html>
|
||||
9
templates/resultat_ajout.html
Normal file
9
templates/resultat_ajout.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head><meta charset="utf-8"><title>Ajout OK</title></head>
|
||||
<body>
|
||||
<h1>Contact ajouté</h1>
|
||||
<p>{{ nom }} → {{ numero }}</p>
|
||||
<p><a href="{{ url_for('index') }}">Retour accueil</a></p>
|
||||
</body>
|
||||
</html>
|
||||
11
templates/resultat_recherche.html
Normal file
11
templates/resultat_recherche.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head><meta charset="utf-8"><title>Résultat</title></head>
|
||||
<body>
|
||||
<h1>Résultat recherche</h1>
|
||||
<p>Nom : {{ nom }}</p>
|
||||
<p>Numéro : {{ numero }}</p>
|
||||
<p><a href="{{ url_for('cherche') }}">Nouvelle recherche</a></p>
|
||||
<p><a href="{{ url_for('index') }}">Retour a l'acceuil</a></p>
|
||||
</body>
|
||||
</html>
|
||||
9
templates/script_mot_de_passe.js
Normal file
9
templates/script_mot_de_passe.js
Normal file
@@ -0,0 +1,9 @@
|
||||
var msg1 = "Bonjour"
|
||||
//Première boîte
|
||||
alert(msg1);
|
||||
//deuxième boîte
|
||||
Identifiant = prompt("Identifiant","Identifiant");
|
||||
//Troisième boîte
|
||||
Mot_de_passe = prompt("Mot de passe","mot de passe");
|
||||
var msg3 = "Bienvenue"+Identifiant
|
||||
alert(msg3);
|
||||
17
templates/user_search.html
Normal file
17
templates/user_search.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Recherche</title>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
||||
</head>
|
||||
<body>
|
||||
<div style = "background-color: red;display: {{display}};"><h1 style="color: yellow;";>VOUS N'AVEZ PAS DE COMPTE</h1></div>
|
||||
<h1>Rechercher</h1>
|
||||
<form action="{{ url_for('result_search') }}" method="post">
|
||||
<label>Identifiant : <input name="Identifiant" required></label>
|
||||
<label>Mot_de_passe : <input name="Mot_de_passe" required></label>
|
||||
<button type="submit">connection</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user