From 9187f41e17a817074c7656cdb49a6a98c8c594b3 Mon Sep 17 00:00:00 2001 From: No4m Date: Mon, 27 Oct 2025 20:35:12 +0100 Subject: [PATCH] first commit --- .idea/.gitignore | 8 +++++ .idea/ProjetCMS-Noam.iml | 8 +++++ .idea/modules.xml | 8 +++++ .idea/php.xml | 22 +++++++++++++ Dockerfile | 9 ++++++ admin/add.php | 48 +++++++++++++++++++++++++++ admin/board.php | 29 +++++++++++++++++ admin/delete.php | 45 ++++++++++++++++++++++++++ admin/login.php | 28 ++++++++++++++++ admin/logout.php | 17 ++++++++++ admin/modif.php | 57 ++++++++++++++++++++++++++++++++ article.php | 18 +++++++++++ assets/style.css | 68 +++++++++++++++++++++++++++++++++++++++ bdd/Dockerfile | 8 +++++ bdd/init.sql | 20 ++++++++++++ include/authenticator.php | 31 ++++++++++++++++++ include/db.php | 13 ++++++++ index.php | 42 ++++++++++++++++++++++++ launch-dockers.sh | 25 ++++++++++++++ 19 files changed, 504 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/ProjetCMS-Noam.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/php.xml create mode 100644 Dockerfile create mode 100644 admin/add.php create mode 100644 admin/board.php create mode 100644 admin/delete.php create mode 100644 admin/login.php create mode 100644 admin/logout.php create mode 100644 admin/modif.php create mode 100644 article.php create mode 100644 assets/style.css create mode 100644 bdd/Dockerfile create mode 100644 bdd/init.sql create mode 100644 include/authenticator.php create mode 100644 include/db.php create mode 100644 index.php create mode 100644 launch-dockers.sh diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/ProjetCMS-Noam.iml b/.idea/ProjetCMS-Noam.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/ProjetCMS-Noam.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..7bab21f --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..8e445c2 --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0f39774 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM php:8.2-apache +LABEL authors="matthieulmr" + +COPY . /var/www/html +WORKDIR /var/www/html + +RUN docker-php-ext-install pdo pdo_mysql + +EXPOSE 80 \ No newline at end of file diff --git a/admin/add.php b/admin/add.php new file mode 100644 index 0000000..2c1088b --- /dev/null +++ b/admin/add.php @@ -0,0 +1,48 @@ +prepare('INSERT INTO articles (titre, contenu, date_creation) VALUES (:titre, :contenu, :date)'); + $stmt->execute([ + ':titre' => $titre, + ':contenu' => $contenu, + ':date' => date('Y-m-d H:i:s'), + ]); + header('Location:board.php'); + exit; + } +} +?> + + + + + Ajouter un article + + + +

Ajouter un article

+ +

+ +
+
+
+ + Annuler +
+ + \ No newline at end of file diff --git a/admin/board.php b/admin/board.php new file mode 100644 index 0000000..50d0e30 --- /dev/null +++ b/admin/board.php @@ -0,0 +1,29 @@ +query('SELECT * FROM articles ORDER BY date_creation DESC'); +$articles = $stmt->fetchAll(); +?> + + +Admin - Tableau de bord + +

Tableau de bord

+Ajouter un article | Se déconnecter + + + + + + + + + +
IDTitreActions
+Modifier | +Supprimer +
+ + \ No newline at end of file diff --git a/admin/delete.php b/admin/delete.php new file mode 100644 index 0000000..1e5f327 --- /dev/null +++ b/admin/delete.php @@ -0,0 +1,45 @@ +prepare('SELECT id, titre FROM articles WHERE id = :id'); +$stmt->execute([':id' => $id]); +$article = $stmt->fetch(); +if (!$article) { + header('Location: board.php'); + exit; +} + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (isset($_POST['confirm']) && $_POST['confirm'] === 'yes') { + $d = $pdo->prepare('DELETE FROM articles WHERE id = :id'); + $d->execute([':id' => $id]); + } + header('Location: board.php'); + exit; +} +?> + + + + + Supprimer l'article + + + +

Supprimer l'article

+

Êtes-vous sûr de vouloir supprimer : ?

+
+ + Annuler +
+ + \ No newline at end of file diff --git a/admin/login.php b/admin/login.php new file mode 100644 index 0000000..6b5352b --- /dev/null +++ b/admin/login.php @@ -0,0 +1,28 @@ + + + +Connexion + +

Connexion

+
+
+
+ +
+

+ + \ No newline at end of file diff --git a/admin/logout.php b/admin/logout.php new file mode 100644 index 0000000..7fbd8e9 --- /dev/null +++ b/admin/logout.php @@ -0,0 +1,17 @@ +prepare('SELECT * FROM articles WHERE id = :id'); +$stmt->execute([':id' => $id]); +$article = $stmt->fetch(); +if (!$article) { + header('Location: board.php'); + exit; +} + +$errors = []; +$titre = $article['titre']; +$contenu = $article['contenu']; + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $titre = trim($_POST['titre'] ?? ''); + $contenu = trim($_POST['contenu'] ?? ''); + if ($titre === '' || $contenu === '') { + $errors[] = 'Tous les champs sont obligatoires.'; + } else { + $u = $pdo->prepare('UPDATE articles SET titre = :titre, contenu = :contenu WHERE id = :id'); + $u->execute([':titre' => $titre, ':contenu' => $contenu, ':id' => $id]); + header('Location: board.php'); + exit; + } +} +?> + + + + + Modifier l'article + + + +

Modifier l'article

+ +

+ +
+
+
+ + Annuler +
+ + \ No newline at end of file diff --git a/article.php b/article.php new file mode 100644 index 0000000..b0222fb --- /dev/null +++ b/article.php @@ -0,0 +1,18 @@ +prepare('SELECT * FROM articles WHERE id = ?'); +$stmt->execute([$id]); +$article = $stmt->fetch(); +if (!$article) { http_response_code(404); die('

404 - Article introuvable

'); } +?> + + +<?= htmlspecialchars($article['titre']) ?> + +

+

+Retour + + \ No newline at end of file diff --git a/assets/style.css b/assets/style.css new file mode 100644 index 0000000..62a5203 --- /dev/null +++ b/assets/style.css @@ -0,0 +1,68 @@ +body { + font-family: Arial, sans-serif; + line-height: 1.6; + margin: 0; + padding: 20px; + background-color: #f4f4f4; + color: #333; +} + +header { + background: #333; + color: #fff; + padding: 10px 0; + text-align: center; + margin-bottom: 20px; +} + +h1 { + color: #444; + border-bottom: 2px solid #ccc; + padding-bottom: 10px; + margin-top: 0; +} + +article { + background: #fff; + padding: 15px; + margin-bottom: 15px; + border: 1px solid #ddd; + border-radius: 5px; + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05); +} + +article h2 a { + color: #007BFF; + text-decoration: none; +} + +article h2 a:hover { + text-decoration: underline; +} + +/* Style spécifique pour l'Admin */ +table { + width: 100%; + border-collapse: collapse; + margin-top: 20px; +} + +table th, table td { + padding: 10px; + border: 1px solid #ccc; + text-align: left; +} + +table th { + background-color: #e2e2e2; +} + +/* Style pour les messages d'erreur */ +.error { + color: red; + font-weight: bold; + border: 1px solid red; + padding: 10px; + background: #ffe6e6; + border-radius: 5px; +} \ No newline at end of file diff --git a/bdd/Dockerfile b/bdd/Dockerfile new file mode 100644 index 0000000..22e35ab --- /dev/null +++ b/bdd/Dockerfile @@ -0,0 +1,8 @@ +FROM mysql +LABEL authors="matthieulmr" + +ENV MYSQL_ROOT_PASSWORD='passwordRoot' + +COPY ./init.sql /docker-entrypoint-initdb.d/ + +EXPOSE 3306 \ No newline at end of file diff --git a/bdd/init.sql b/bdd/init.sql new file mode 100644 index 0000000..9bacfb3 --- /dev/null +++ b/bdd/init.sql @@ -0,0 +1,20 @@ +CREATE DATABASE IF NOT EXISTS cms_simpli CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +USE cms_simpli; + +CREATE TABLE utilisateur ( +id INT AUTO_INCREMENT PRIMARY KEY, +login VARCHAR(50) UNIQUE NOT NULL, +password VARCHAR(255) NOT NULL +); + + +CREATE TABLE articles ( +id INT AUTO_INCREMENT PRIMARY KEY, +titre VARCHAR(255) NOT NULL, +contenu TEXT NOT NULL, +date_creation DATETIME DEFAULT CURRENT_TIMESTAMP +); + + +INSERT INTO utilisateur (login, password) VALUES ('admin', '$2y$10$OVqu798zF7FF36HER0nZ9uOJ5tuuTR.kwPK2GTiqlPPYzR2szGzB6'); \ No newline at end of file diff --git a/include/authenticator.php b/include/authenticator.php new file mode 100644 index 0000000..b398e83 --- /dev/null +++ b/include/authenticator.php @@ -0,0 +1,31 @@ +prepare('SELECT * FROM utilisateur WHERE login = ?'); +$stmt->execute([$login]); +$user = $stmt->fetch(); + + +if ($user && password_verify($password, $user['password'])) { +$_SESSION['user'] = $user['login']; +return true; +} +return false; +} + + +function requireLogin() { +if (!isLogged()) { +header('Location: login.php'); +exit; +} +} \ No newline at end of file diff --git a/include/db.php b/include/db.php new file mode 100644 index 0000000..b8f285c --- /dev/null +++ b/include/db.php @@ -0,0 +1,13 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +} catch (PDOException $e) { + die('Erreur de connexion : ' . $e->getMessage()); +} \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..dfdc0bb --- /dev/null +++ b/index.php @@ -0,0 +1,42 @@ +query('SELECT * FROM articles ORDER BY date_creation DESC LIMIT 10'); +$articles = $stmt->fetchAll(); +?> + + + + + Accueil - CMS Simplifié + + + +
+ +
+ +
+

Articles récents

+ +

Aucun article n'a encore été publié.

+ + + + + +
+ + + + \ No newline at end of file diff --git a/launch-dockers.sh b/launch-dockers.sh new file mode 100644 index 0000000..e1eb597 --- /dev/null +++ b/launch-dockers.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +docker stop CMS_mysql + +docker stop CMS_php + +docker rm CMS_mysql + +docker rm CMS_php + +docker network rm CMS-bridge + +docker network create -d bridge CMS-bridge + +cd bdd + +docker build -t cms_mysql . + +docker run -d --name CMS_mysql -p 3306:3306 --network=CMS-bridge cms_mysql:latest + +cd .. + +docker build -t cms_php . + +docker run -d --name CMS_php -p 8080:80 --network=CMS-bridge cms_php:latest