This commit is contained in:
No4m
2025-11-02 14:05:02 +01:00
parent 9187f41e17
commit f2b78086dd
13 changed files with 122 additions and 74 deletions

View File

@@ -2,6 +2,9 @@ FROM php:8.2-apache
LABEL authors="matthieulmr" LABEL authors="matthieulmr"
COPY . /var/www/html COPY . /var/www/html
RUN chown -R www-data:www-data /var/www/html
WORKDIR /var/www/html WORKDIR /var/www/html
RUN docker-php-ext-install pdo pdo_mysql RUN docker-php-ext-install pdo pdo_mysql

14
README.md Normal file
View File

@@ -0,0 +1,14 @@
Pour accéder au site :
Lancez les conteneurs depuis la racine du projet avec la commande suivante (Dans un terminal qui accepte le bash par exemple GIT bash) :
./launch-dockers.sh
Une fois les conteneurs démarrés, le site sera accessible dans votre navigateur à l'adresse :
http://localhost:8080/
Acces au compte admin :
Utilisateur : Admin
Mdp : Ciccina28

View File

@@ -1,7 +1,6 @@
<?php <?php
global $pdo, $pdo;
require '../include/db.php'; require '../include/db.php';
require '../include/authenticator.php'; require '../include/auth.php';
requireLogin(); requireLogin();
$errors = []; $errors = [];
@@ -26,14 +25,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
} }
} }
?> ?>
<!doctype html> <!doctype html>
<html lang="fr"> <html lang="fr">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Ajouter un article</title> <title>Ajouter un article</title>
<link rel="stylesheet" href="/assets/style.css"> <link rel="stylesheet" href="/assets/style.css">
</head> </head>
<body> <body>
<h1>Ajouter un article</h1> <h1>Ajouter un article</h1>
<?php foreach ($errors as $e): ?> <?php foreach ($errors as $e): ?>
<p class="error"><?= htmlspecialchars($e) ?></p> <p class="error"><?= htmlspecialchars($e) ?></p>
@@ -44,5 +44,5 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<button type="submit">Publier</button> <button type="submit">Publier</button>
<a href="board.php">Annuler</a> <a href="board.php">Annuler</a>
</form> </form>
</body> </body>
</html> </html>

View File

@@ -1,29 +1,29 @@
<?php <?php
global $pdo;
require '../include/db.php'; require '../include/db.php';
require '../include/authenticator.php'; require '../include/auth.php';
requireLogin(); requireLogin();
$stmt = $pdo->query('SELECT * FROM articles ORDER BY date_creation DESC'); $stmt = $pdo->query('SELECT * FROM articles ORDER BY date_creation DESC');
$articles = $stmt->fetchAll(); $articles = $stmt->fetchAll();
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="fr"> <html lang="fr">
<head><meta charset="UTF-8"><title>Admin - Tableau de bord</title></head> <head><meta charset="UTF-8"><title>Admin - Tableau de bord</title></head>
<body> <body>
<h1>Tableau de bord</h1> <h1>Tableau de bord</h1>
<a href="add.php">Ajouter un article</a> | <a href="logout.php">Se déconnecter</a> <a href="add.php">Ajouter un article</a> | <a href="logout.php">Se déconnecter</a>
<table border="1"> <table border="1">
<tr><th>ID</th><th>Titre</th><th>Actions</th></tr> <tr><th>ID</th><th>Titre</th><th>Actions</th></tr>
<?php foreach ($articles as $a): ?> <?php foreach ($articles as $a): ?>
<tr> <tr>
<td><?= $a['id'] ?></td> <td><?= $a['id'] ?></td>
<td><?= htmlspecialchars($a['titre']) ?></td> <td><?= htmlspecialchars($a['titre']) ?></td>
<td> <td>
<a href="modif.php?id=<?= $a['id'] ?>">Modifier</a> | <a href="modif.php?id=<?= $a['id'] ?>">Modifier</a> |
<a href="delete.php?id=<?= $a['id'] ?>">Supprimer</a> <a href="delete.php?id=<?= $a['id'] ?>">Supprimer</a>
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</table> </table>
</body> </body>
</html> </html>

View File

@@ -1,7 +1,6 @@
<?php <?php
global $pdo;
require '../include/db.php'; require '../include/db.php';
require '../include/authenticator.php'; require '../include/auth.php';
requireLogin(); requireLogin();
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0; $id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
@@ -27,19 +26,20 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
exit; exit;
} }
?> ?>
<!doctype html> <!doctype html>
<html lang="fr"> <html lang="fr">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Supprimer l'article</title> <title>Supprimer l'article</title>
<link rel="stylesheet" href="/assets/style.css"> <link rel="stylesheet" href="/assets/style.css">
</head> </head>
<body> <body>
<h1>Supprimer l'article</h1> <h1>Supprimer l'article</h1>
<p>Êtes-vous sûr de vouloir supprimer : <strong><?= htmlspecialchars($article['titre']) ?></strong> ?</p> <p>Êtes-vous sûr de vouloir supprimer : <strong><?= htmlspecialchars($article['titre']) ?></strong> ?</p>
<form method="post"> <form method="post">
<button type="submit" name="confirm" value="yes">Oui, supprimer</button> <button type="submit" name="confirm" value="yes">Oui, supprimer</button>
<a href="board.php">Annuler</a> <a href="board.php">Annuler</a>
</form> </form>
</body> </body>
</html> </html>

View File

@@ -1,7 +1,6 @@
<?php <?php
global $pdo;
require '../include/db.php'; require '../include/db.php';
require '../include/authenticator.php'; require '../include/auth.php';
$error = ''; $error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($_SERVER['REQUEST_METHOD'] === 'POST') {
@@ -13,16 +12,17 @@ $error = 'Identifiants incorrects';
} }
} }
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="fr"> <html lang="fr">
<head><meta charset="UTF-8"><title>Connexion</title></head> <head><meta charset="UTF-8"><title>Connexion</title></head>
<body> <body>
<h1>Connexion</h1> <h1>Connexion</h1>
<form method="post"> <form method="post">
<input type="text" name="login" placeholder="Login" required><br> <input type="text" name="login" placeholder="Login" required><br>
<input type="password" name="password" placeholder="Mot de passe" required><br> <input type="password" name="password" placeholder="Mot de passe" required><br>
<button type="submit">Se connecter</button> <button type="submit">Se connecter</button>
</form> </form>
<p style="color:red;"><?= $error ?></p> <p style="color:red;"><?= $error ?></p>
</body> </body>
</html> </html>

View File

@@ -1,5 +1,4 @@
<?php <?php
global $pdo;
require 'include/db.php'; require 'include/db.php';
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0; $id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
$stmt = $pdo->prepare('SELECT * FROM articles WHERE id = ?'); $stmt = $pdo->prepare('SELECT * FROM articles WHERE id = ?');
@@ -7,6 +6,7 @@ $stmt->execute([$id]);
$article = $stmt->fetch(); $article = $stmt->fetch();
if (!$article) { http_response_code(404); die('<h1>404 - Article introuvable</h1>'); } if (!$article) { http_response_code(404); die('<h1>404 - Article introuvable</h1>'); }
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="fr"> <html lang="fr">
<head><meta charset="UTF-8"><title><?= htmlspecialchars($article['titre']) ?></title></head> <head><meta charset="UTF-8"><title><?= htmlspecialchars($article['titre']) ?></title></head>

View File

@@ -4,11 +4,11 @@ body {
margin: 0; margin: 0;
padding: 20px; padding: 20px;
background-color: #f4f4f4; background-color: #f4f4f4;
color: #333; color: #ffffff;
} }
header { header {
background: #333; background: #ffffff;
color: #fff; color: #fff;
padding: 10px 0; padding: 10px 0;
text-align: center; text-align: center;
@@ -16,7 +16,7 @@ header {
} }
h1 { h1 {
color: #444; color: #ffffff;
border-bottom: 2px solid #ccc; border-bottom: 2px solid #ccc;
padding-bottom: 10px; padding-bottom: 10px;
margin-top: 0; margin-top: 0;
@@ -28,7 +28,7 @@ article {
margin-bottom: 15px; margin-bottom: 15px;
border: 1px solid #ddd; border: 1px solid #ddd;
border-radius: 5px; border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05); box-shadow: 0 2px 4px rgba(253, 249, 249, 0.05);
} }
article h2 a { article h2 a {
@@ -40,7 +40,6 @@ article h2 a:hover {
text-decoration: underline; text-decoration: underline;
} }
/* Style spécifique pour l'Admin */
table { table {
width: 100%; width: 100%;
border-collapse: collapse; border-collapse: collapse;
@@ -57,7 +56,6 @@ table th {
background-color: #e2e2e2; background-color: #e2e2e2;
} }
/* Style pour les messages d'erreur */
.error { .error {
color: red; color: red;
font-weight: bold; font-weight: bold;

View File

@@ -17,4 +17,4 @@ date_creation DATETIME DEFAULT CURRENT_TIMESTAMP
); );
INSERT INTO utilisateur (login, password) VALUES ('admin', '$2y$10$OVqu798zF7FF36HER0nZ9uOJ5tuuTR.kwPK2GTiqlPPYzR2szGzB6'); INSERT INTO utilisateur (login, password) VALUES ('Admin', '$2y$12$Rtdu4PVCMi0hvY43vxAIN.1K7TmNxYwaE/idie5B3C1K45TKdobzq');

32
include/auth.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
session_start();
function isLogged(): bool
{
return isset($_SESSION['user']);
}
function checkLogin(PDO $pdo, $login, $password): bool
{
$stmt = $pdo->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;
}
}
?>

View File

@@ -11,3 +11,4 @@ try {
} catch (PDOException $e) { } catch (PDOException $e) {
die('Erreur de connexion : ' . $e->getMessage()); die('Erreur de connexion : ' . $e->getMessage());
} }
?>

View File

@@ -1,9 +1,9 @@
<?php <?php
global $pdo;
require 'include/db.php'; require 'include/db.php';
$stmt = $pdo->query('SELECT * FROM articles ORDER BY date_creation DESC LIMIT 10'); $stmt = $pdo->query('SELECT * FROM articles ORDER BY date_creation DESC LIMIT 10');
$articles = $stmt->fetchAll(); $articles = $stmt->fetchAll();
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="fr"> <html lang="fr">
<head> <head>

0
launch-dockers.sh Normal file → Executable file
View File