From 17a16feb2db75899513a5ad3a8e6903ec99b8e80 Mon Sep 17 00:00:00 2001 From: "JARNOUEN DE VILLARTAY Ulysse (SAFRAN AIRCRAFT ENGINES)" Date: Wed, 15 Apr 2026 16:20:11 +0200 Subject: [PATCH] ex3 --- .env.example | 4 + .gitignore | 1 + R3.01/tp/tp3/cinema/sql/cinema.sql | 8 ++ R3.01/tp/tp3/cinema/src/authentification.php | 46 +++++++++ R3.01/tp/tp3/cinema/src/deconnexion.php | 14 +++ R3.01/tp/tp3/cinema/src/films.php | 12 +-- R3.01/tp/tp3/cinema/src/inscription.php | 98 +++++++++++++++++++ R3.01/tp/tp3/cinema/src/modeles/connexion.php | 33 +++++++ .../tp/tp3/cinema/src/modeles/modeleFilms.php | 34 ++++--- .../cinema/src/modeles/modeleUtilisateurs.php | 53 ++++++++++ R3.01/tp/tp3/cinema/src/securite.php | 11 +++ R3.01/tp/tp3/cinema/src/verification.php | 35 +++++++ R3.01/tp/tp3/cinema/src/vues/header.php | 32 +++--- 13 files changed, 353 insertions(+), 28 deletions(-) create mode 100644 .env.example create mode 100644 R3.01/tp/tp3/cinema/src/authentification.php create mode 100644 R3.01/tp/tp3/cinema/src/deconnexion.php create mode 100644 R3.01/tp/tp3/cinema/src/inscription.php create mode 100644 R3.01/tp/tp3/cinema/src/modeles/connexion.php create mode 100644 R3.01/tp/tp3/cinema/src/modeles/modeleUtilisateurs.php create mode 100644 R3.01/tp/tp3/cinema/src/securite.php create mode 100644 R3.01/tp/tp3/cinema/src/verification.php diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..cd5bda4 --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +CINEMA_DB_HOST=dwarves.iut-fbleau.fr +CINEMA_DB_USER=foo +CINEMA_DB_PASSWORD=foo +CINEMA_DB_NAME=foo \ No newline at end of file diff --git a/.gitignore b/.gitignore index c60b300..cc0e85f 100644 --- a/.gitignore +++ b/.gitignore @@ -328,3 +328,4 @@ TSWLatexianTemp* # Uncomment the next line to have this generated file ignored. #*Notes.bib +.env \ No newline at end of file diff --git a/R3.01/tp/tp3/cinema/sql/cinema.sql b/R3.01/tp/tp3/cinema/sql/cinema.sql index d53b5aa..e54eef6 100644 --- a/R3.01/tp/tp3/cinema/sql/cinema.sql +++ b/R3.01/tp/tp3/cinema/sql/cinema.sql @@ -19,6 +19,14 @@ SET time_zone = "+00:00"; -- -------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `user` ( + login VARCHAR(50) NOT NULL, + email VARCHAR(255) NOT NULL, + password VARCHAR(255) NOT NULL, + PRIMARY KEY (login) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + -- -- Table structure for table `Artiste` -- diff --git a/R3.01/tp/tp3/cinema/src/authentification.php b/R3.01/tp/tp3/cinema/src/authentification.php new file mode 100644 index 0000000..60fc8b7 --- /dev/null +++ b/R3.01/tp/tp3/cinema/src/authentification.php @@ -0,0 +1,46 @@ + + + + + + Authentification + + + +
+

Authentification

+ + +
Inscription réussie. Vous pouvez maintenant vous connecter.
+ + + +
Vous avez été déconnecté.
+ + + +
Login ou mot de passe incorrect.
+ + +
+ + + + + + + +
+ +

Créer un compte

+
+ + \ No newline at end of file diff --git a/R3.01/tp/tp3/cinema/src/deconnexion.php b/R3.01/tp/tp3/cinema/src/deconnexion.php new file mode 100644 index 0000000..5b74acc --- /dev/null +++ b/R3.01/tp/tp3/cinema/src/deconnexion.php @@ -0,0 +1,14 @@ + +include_once './vues/header.php'; +include_once './vues/vueFilms.php'; +include_once './vues/footer.php'; diff --git a/R3.01/tp/tp3/cinema/src/inscription.php b/R3.01/tp/tp3/cinema/src/inscription.php new file mode 100644 index 0000000..aa0117c --- /dev/null +++ b/R3.01/tp/tp3/cinema/src/inscription.php @@ -0,0 +1,98 @@ + '', + 'email' => '', +); + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $values['login'] = isset($_POST['login']) ? trim($_POST['login']) : ''; + $values['email'] = isset($_POST['email']) ? trim($_POST['email']) : ''; + $password = isset($_POST['password']) ? $_POST['password'] : ''; + + // On valide champ par champ pour pouvoir réafficher proprement le formulaire. + if ($values['login'] === '') { + $errors['login'] = 'Le login est obligatoire.'; + } elseif (!preg_match('/^[a-zA-Z0-9_-]{3,30}$/', $values['login'])) { + $errors['login'] = 'Le login doit contenir entre 3 et 30 caractères alphanumériques, _ ou -.'; + } + + if ($values['email'] === '') { + $errors['email'] = 'L\'email est obligatoire.'; + } elseif (!filter_var($values['email'], FILTER_VALIDATE_EMAIL)) { + $errors['email'] = 'Le format de l\'email est invalide.'; + } + + if ($password === '') { + $errors['password'] = 'Le mot de passe est obligatoire.'; + } elseif (strlen($password) < 8) { + $errors['password'] = 'Le mot de passe doit contenir au moins 8 caractères.'; + } + + if ($values['login'] !== '' && findUserByLogin($values['login']) !== null) { + $errors['login'] = 'Ce login est déjà utilisé.'; + } + + if (empty($errors)) { + $passwordHash = password_hash($password, PASSWORD_DEFAULT); + createUser($values['login'], $values['email'], $passwordHash); + + header('Location: ./authentification.php?registered=1'); + exit; + } +} +?> + + + + + Inscription + + + +
+

Inscription

+

Créez un compte avant d'accéder aux pages du site.

+ +
+ + + + + + + + + + + + + + + + + + + +
+ +

Déjà inscrit ? Se connecter

+
+ + \ No newline at end of file diff --git a/R3.01/tp/tp3/cinema/src/modeles/connexion.php b/R3.01/tp/tp3/cinema/src/modeles/connexion.php new file mode 100644 index 0000000..d8a7378 --- /dev/null +++ b/R3.01/tp/tp3/cinema/src/modeles/connexion.php @@ -0,0 +1,33 @@ + diff --git a/R3.01/tp/tp3/cinema/src/modeles/modeleUtilisateurs.php b/R3.01/tp/tp3/cinema/src/modeles/modeleUtilisateurs.php new file mode 100644 index 0000000..9436318 --- /dev/null +++ b/R3.01/tp/tp3/cinema/src/modeles/modeleUtilisateurs.php @@ -0,0 +1,53 @@ + $dbLogin, + 'email' => $dbEmail, + 'password' => $dbPassword, + ); + } + + mysqli_stmt_close($stmt); + + return $user; +} + +function createUser($login, $email, $passwordHash) +{ + $conn = getConnection(); + $stmt = mysqli_prepare($conn, 'INSERT INTO `user` (login, email, password) VALUES (?, ?, ?)'); + if ($stmt === false) { + die('Préparation SQL impossible : ' . mysqli_error($conn)); + } + + mysqli_stmt_bind_param($stmt, 'sss', $login, $email, $passwordHash); + $success = mysqli_stmt_execute($stmt); + $errorCode = mysqli_errno($conn); + mysqli_stmt_close($stmt); + + // 1062 = violation de clé unique (login déjà pris). + if (!$success && $errorCode === 1062) { + return false; + } + + if (!$success) { + die('Insertion SQL impossible : ' . mysqli_error($conn)); + } + + return true; +} diff --git a/R3.01/tp/tp3/cinema/src/securite.php b/R3.01/tp/tp3/cinema/src/securite.php new file mode 100644 index 0000000..89125e3 --- /dev/null +++ b/R3.01/tp/tp3/cinema/src/securite.php @@ -0,0 +1,11 @@ + - - - Films - + + + Films + - - - -
+ + + +
+