commit1
This commit is contained in:
@@ -2,6 +2,9 @@ FROM php:8.2-apache
|
||||
LABEL authors="matthieulmr"
|
||||
|
||||
COPY . /var/www/html
|
||||
|
||||
RUN chown -R www-data:www-data /var/www/html
|
||||
|
||||
WORKDIR /var/www/html
|
||||
|
||||
RUN docker-php-ext-install pdo pdo_mysql
|
||||
|
||||
14
README.md
Normal file
14
README.md
Normal 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
|
||||
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
global $pdo, $pdo;
|
||||
require '../include/db.php';
|
||||
require '../include/authenticator.php';
|
||||
require '../include/auth.php';
|
||||
requireLogin();
|
||||
|
||||
$errors = [];
|
||||
@@ -26,23 +25,24 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Ajouter un article</title>
|
||||
<link rel="stylesheet" href="/assets/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Ajouter un article</h1>
|
||||
<?php foreach ($errors as $e): ?>
|
||||
<p class="error"><?= htmlspecialchars($e) ?></p>
|
||||
<?php endforeach; ?>
|
||||
<form method="post">
|
||||
<label>Titre<br><input type="text" name="titre" value="<?= htmlspecialchars($titre) ?>" required></label><br>
|
||||
<label>Contenu<br><textarea name="contenu" rows="10" required><?= htmlspecialchars($contenu) ?></textarea></label><br>
|
||||
<button type="submit">Publier</button>
|
||||
<a href="board.php">Annuler</a>
|
||||
</form>
|
||||
</body>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Ajouter un article</title>
|
||||
<link rel="stylesheet" href="/assets/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Ajouter un article</h1>
|
||||
<?php foreach ($errors as $e): ?>
|
||||
<p class="error"><?= htmlspecialchars($e) ?></p>
|
||||
<?php endforeach; ?>
|
||||
<form method="post">
|
||||
<label>Titre<br><input type="text" name="titre" value="<?= htmlspecialchars($titre) ?>" required></label><br>
|
||||
<label>Contenu<br><textarea name="contenu" rows="10" required><?= htmlspecialchars($contenu) ?></textarea></label><br>
|
||||
<button type="submit">Publier</button>
|
||||
<a href="board.php">Annuler</a>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,29 +1,29 @@
|
||||
<?php
|
||||
global $pdo;
|
||||
require '../include/db.php';
|
||||
require '../include/authenticator.php';
|
||||
require '../include/auth.php';
|
||||
requireLogin();
|
||||
$stmt = $pdo->query('SELECT * FROM articles ORDER BY date_creation DESC');
|
||||
$articles = $stmt->fetchAll();
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head><meta charset="UTF-8"><title>Admin - Tableau de bord</title></head>
|
||||
<body>
|
||||
<h1>Tableau de bord</h1>
|
||||
<a href="add.php">Ajouter un article</a> | <a href="logout.php">Se déconnecter</a>
|
||||
<table border="1">
|
||||
<tr><th>ID</th><th>Titre</th><th>Actions</th></tr>
|
||||
<?php foreach ($articles as $a): ?>
|
||||
<tr>
|
||||
<td><?= $a['id'] ?></td>
|
||||
<td><?= htmlspecialchars($a['titre']) ?></td>
|
||||
<td>
|
||||
<a href="modif.php?id=<?= $a['id'] ?>">Modifier</a> |
|
||||
<a href="delete.php?id=<?= $a['id'] ?>">Supprimer</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</body>
|
||||
<body>
|
||||
<h1>Tableau de bord</h1>
|
||||
<a href="add.php">Ajouter un article</a> | <a href="logout.php">Se déconnecter</a>
|
||||
<table border="1">
|
||||
<tr><th>ID</th><th>Titre</th><th>Actions</th></tr>
|
||||
<?php foreach ($articles as $a): ?>
|
||||
<tr>
|
||||
<td><?= $a['id'] ?></td>
|
||||
<td><?= htmlspecialchars($a['titre']) ?></td>
|
||||
<td>
|
||||
<a href="modif.php?id=<?= $a['id'] ?>">Modifier</a> |
|
||||
<a href="delete.php?id=<?= $a['id'] ?>">Supprimer</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
global $pdo;
|
||||
require '../include/db.php';
|
||||
require '../include/authenticator.php';
|
||||
require '../include/auth.php';
|
||||
requireLogin();
|
||||
|
||||
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
||||
@@ -27,19 +26,20 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Supprimer l'article</title>
|
||||
<link rel="stylesheet" href="/assets/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Supprimer l'article</h1>
|
||||
<p>Êtes-vous sûr de vouloir supprimer : <strong><?= htmlspecialchars($article['titre']) ?></strong> ?</p>
|
||||
<form method="post">
|
||||
<button type="submit" name="confirm" value="yes">Oui, supprimer</button>
|
||||
<a href="board.php">Annuler</a>
|
||||
</form>
|
||||
</body>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Supprimer l'article</title>
|
||||
<link rel="stylesheet" href="/assets/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Supprimer l'article</h1>
|
||||
<p>Êtes-vous sûr de vouloir supprimer : <strong><?= htmlspecialchars($article['titre']) ?></strong> ?</p>
|
||||
<form method="post">
|
||||
<button type="submit" name="confirm" value="yes">Oui, supprimer</button>
|
||||
<a href="board.php">Annuler</a>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
global $pdo;
|
||||
require '../include/db.php';
|
||||
require '../include/authenticator.php';
|
||||
require '../include/auth.php';
|
||||
|
||||
$error = '';
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
@@ -13,16 +12,17 @@ $error = 'Identifiants incorrects';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head><meta charset="UTF-8"><title>Connexion</title></head>
|
||||
<body>
|
||||
<h1>Connexion</h1>
|
||||
<form method="post">
|
||||
<input type="text" name="login" placeholder="Login" required><br>
|
||||
<input type="password" name="password" placeholder="Mot de passe" required><br>
|
||||
<button type="submit">Se connecter</button>
|
||||
</form>
|
||||
<p style="color:red;"><?= $error ?></p>
|
||||
</body>
|
||||
<body>
|
||||
<h1>Connexion</h1>
|
||||
<form method="post">
|
||||
<input type="text" name="login" placeholder="Login" required><br>
|
||||
<input type="password" name="password" placeholder="Mot de passe" required><br>
|
||||
<button type="submit">Se connecter</button>
|
||||
</form>
|
||||
<p style="color:red;"><?= $error ?></p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
global $pdo;
|
||||
require 'include/db.php';
|
||||
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
||||
$stmt = $pdo->prepare('SELECT * FROM articles WHERE id = ?');
|
||||
@@ -7,6 +6,7 @@ $stmt->execute([$id]);
|
||||
$article = $stmt->fetch();
|
||||
if (!$article) { http_response_code(404); die('<h1>404 - Article introuvable</h1>'); }
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head><meta charset="UTF-8"><title><?= htmlspecialchars($article['titre']) ?></title></head>
|
||||
|
||||
@@ -4,11 +4,11 @@ body {
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
background-color: #f4f4f4;
|
||||
color: #333;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
header {
|
||||
background: #333;
|
||||
background: #ffffff;
|
||||
color: #fff;
|
||||
padding: 10px 0;
|
||||
text-align: center;
|
||||
@@ -16,7 +16,7 @@ header {
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #444;
|
||||
color: #ffffff;
|
||||
border-bottom: 2px solid #ccc;
|
||||
padding-bottom: 10px;
|
||||
margin-top: 0;
|
||||
@@ -28,7 +28,7 @@ article {
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid #ddd;
|
||||
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 {
|
||||
@@ -40,7 +40,6 @@ article h2 a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* Style spécifique pour l'Admin */
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
@@ -57,7 +56,6 @@ table th {
|
||||
background-color: #e2e2e2;
|
||||
}
|
||||
|
||||
/* Style pour les messages d'erreur */
|
||||
.error {
|
||||
color: red;
|
||||
font-weight: bold;
|
||||
|
||||
@@ -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
32
include/auth.php
Normal 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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -11,3 +11,4 @@ try {
|
||||
} catch (PDOException $e) {
|
||||
die('Erreur de connexion : ' . $e->getMessage());
|
||||
}
|
||||
?>
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
global $pdo;
|
||||
require 'include/db.php';
|
||||
$stmt = $pdo->query('SELECT * FROM articles ORDER BY date_creation DESC LIMIT 10');
|
||||
$articles = $stmt->fetchAll();
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
|
||||
0
launch-dockers.sh
Normal file → Executable file
0
launch-dockers.sh
Normal file → Executable file
Reference in New Issue
Block a user