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,6 +25,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
} }
} }
?> ?>
<!doctype html> <!doctype html>
<html lang="fr"> <html lang="fr">
<head> <head>

View File

@@ -1,11 +1,11 @@
<?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>

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,6 +26,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
exit; exit;
} }
?> ?>
<!doctype html> <!doctype html>
<html lang="fr"> <html lang="fr">
<head> <head>

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,6 +12,7 @@ $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>

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