diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..f6e1d42 --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +DB_HOST=dwarves.iut-fbleau.fr +DB_USER=foo +DB_PASSWORD=foo +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 @@ + $totalPages && $totalFilms > 0) { } // -// on "charge" la vue +// On charge les fichiers de vue une fois les données prêtes. // include_once './vues/header.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..53123d1 --- /dev/null +++ b/R3.01/tp/tp3/cinema/src/modeles/connexion.php @@ -0,0 +1,32 @@ + $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 + - - - -
+ + + +
+ diff --git a/R3.01/tp/tp4/ex1/index.php b/R3.01/tp/tp4/ex1/index.php index b1873cc..ceb9fb3 100644 --- a/R3.01/tp/tp4/ex1/index.php +++ b/R3.01/tp/tp4/ex1/index.php @@ -1,6 +1,27 @@ 'Linux', + 'windows' => 'Windows', + 'apple' => 'MacOS', +]; -include './views/main.php'; -?> +$cookieName = 'preferred_os'; +$os = 'linux'; + +// Si le formulaire est soumis, on valide la valeur reçue avant +// de l'enregistrer dans un cookie valable 60 secondes. +if (isset($_POST['os']) && array_key_exists($_POST['os'], $osSet)) { + $os = $_POST['os']; + setcookie($cookieName, $os, time() + 60); + + // On met aussi $_COOKIE à jour pour refléter immédiatement le choix + // sans attendre le rechargement suivant du navigateur. + $_COOKIE[$cookieName] = $os; +} elseif (isset($_COOKIE[$cookieName]) && array_key_exists($_COOKIE[$cookieName], $osSet)) { + // En l'absence de soumission, on relit la préférence mémorisée. + $os = $_COOKIE[$cookieName]; +} + +include_once './views/main.php'; diff --git a/R3.01/tp/tp4/ex1/views/main.php b/R3.01/tp/tp4/ex1/views/main.php index 2aedb2d..1cbff0c 100644 --- a/R3.01/tp/tp4/ex1/views/main.php +++ b/R3.01/tp/tp4/ex1/views/main.php @@ -1,44 +1,50 @@ - - - - - + + + + Cookie OS préféré + + + + +
+
+
+ Changez votre os + $label) { ?> + + +
- - -
- -
- Changez votre os - - - -
- - - -
-
Votre os
- ";?> -
- Rafraîchir la page -
-
- -
- + + +
+
Votre os
+

+ + +

+

+
+ Rafraîchir la page + + + +
+
+
+ diff --git a/R3.01/tp/tp4/ex2/helpers.php b/R3.01/tp/tp4/ex2/helpers.php index 211e12c..f733f64 100644 --- a/R3.01/tp/tp4/ex2/helpers.php +++ b/R3.01/tp/tp4/ex2/helpers.php @@ -1,54 +1,83 @@ '; - for ($i = 0; $i < 3; $i ++){ - echo ""; - for ($j = 0; $j < 3; $j ++){ + for ($i = 0; $i < 3; $i++) { + echo ''; + for ($j = 0; $j < 3; $j++) { + echo ''; - echo ""; - - $pos = 3*$i + $j; - if ($grid[$pos] == 0) + $pos = 3 * $i + $j; + if ($grid[$pos] == 0 && $isInteractive) { echo ""; - if ($grid[$pos] == 1) + } + if ($grid[$pos] == 1) { echo ''; - if ($grid[$pos] == 2) + } + if ($grid[$pos] == 2) { echo ''; + } - echo ""; + echo ''; } - echo ""; + echo ''; } - echo ""; + echo ''; } diff --git a/R3.01/tp/tp4/ex2/index.php b/R3.01/tp/tp4/ex2/index.php index 2c1717b..6222985 100644 --- a/R3.01/tp/tp4/ex2/index.php +++ b/R3.01/tp/tp4/ex2/index.php @@ -1,11 +1,70 @@ array('min_range' => 0, 'max_range' => 8)) + ); + + if ($pos === false || $pos === null) { + $message = 'Coup invalide.'; + } elseif ($grid[$pos] !== 0) { + $message = 'Cette case est déjà occupée.'; + } else { + // On enregistre le coup du joueur courant dans la grille. + $grid[$pos] = $playerTurn; + + if (isWinner($grid, $playerTurn)) { + $message = "Le joueur $playerTurn gagne la partie."; + } elseif (noWinner($grid)) { + $message = 'Match nul.'; + } else { + $playerTurn = nextPlayer($playerTurn); + } + + $_SESSION['grid'] = $grid; + $_SESSION['playerTurn'] = $playerTurn; + } + + $winner = getWinner($grid); + $isGameOver = $winner !== 0 || noWinner($grid); +} + +// Si la page est simplement rafraîchie, on recalcule un message cohérent +// à partir de l'état stocké en session. +if ($message === '') { + if ($winner !== 0) { + $message = "Le joueur $winner gagne la partie."; + } elseif (noWinner($grid)) { + $message = 'Match nul.'; + } +} + +include_once './views/tictactoe.php'; diff --git a/R3.01/tp/tp4/ex2/views/tictactoe.php b/R3.01/tp/tp4/ex2/views/tictactoe.php index 130bf00..8b16508 100644 --- a/R3.01/tp/tp4/ex2/views/tictactoe.php +++ b/R3.01/tp/tp4/ex2/views/tictactoe.php @@ -1,23 +1,35 @@ - + + + Tic Tac Toe + rel="stylesheet" + href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css" + /> -
-

Tic Tac Toe :

+

+ + Partie terminée + + Tic Tac Toe : joueur à vous de jouer + +

$message new game"; - ?> + if ($message != '') { + echo '
' . htmlspecialchars($message, ENT_QUOTES) . " nouvelle partie
"; + } else { + echo "

Recommencer la partie

"; + } + ?>