Initial commit - mini cms final

This commit is contained in:
Aya Tess tess
2025-11-03 21:53:58 +01:00
parent a366336dc1
commit a01f620ef9
14 changed files with 422 additions and 197 deletions

View File

@@ -1,26 +1,28 @@
<?php
session_start();
require_once "config.php";
include "header.php";
require_once 'config.php';
// Vérifier si le formulaire a été soumis
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$username = trim($_POST["username"]);
$password = password_hash($_POST["password"], PASSWORD_BCRYPT);
$role = "auteur"; // Par défaut, tout nouvel utilisateur est auteur
$message = '';
// Vérifier si le nom d'utilisateur existe déjà
$stmt = $pdo->prepare("SELECT id FROM utilisateurs WHERE username = ?");
$stmt->execute([$username]);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = trim($_POST['username'] ?? '');
$email = trim($_POST['email'] ?? '');
$password = $_POST['password'] ?? '';
if ($stmt->rowCount() > 0) {
echo "<p style='color:red;text-align:center;'>⚠️ Ce nom d'utilisateur existe déjà.</p>";
if ($username && $email && $password) {
$hashedPassword = password_hash($password, PASSWORD_BCRYPT);
$role = 'auteur'; // ✅ tout nouvel utilisateur est un auteur
try {
$stmt = $pdo->prepare("INSERT INTO utilisateurs (username, email, password, role) VALUES (?, ?, ?, ?)");
$stmt->execute([$username, $email, $hashedPassword, $role]);
header("Location: login.php");
exit;
} catch (PDOException $e) {
$message = "❌ Erreur lors de l'inscription : " . $e->getMessage();
}
} else {
// Insérer le nouvel utilisateur
$stmt = $pdo->prepare("INSERT INTO utilisateurs (username, password, role) VALUES (?, ?, ?)");
$stmt->execute([$username, $password, $role]);
echo "<p style='color:green;text-align:center;'>✅ Inscription réussie ! Vous pouvez maintenant vous connecter.</p>";
$message = "⚠️ Tous les champs sont obligatoires.";
}
}
?>
@@ -29,70 +31,58 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Inscription - Mini CMS</title>
<title>Créer un compte ✨</title>
<style>
body {
background: linear-gradient(135deg, #ffb6c1, #ffa07a);
font-family: 'Poppins', sans-serif;
margin: 0;
height: 100vh;
background: linear-gradient(120deg, #ffe0ec, #fff6f8);
display: flex;
justify-content: center;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
}
.container {
background: white;
padding: 40px;
border-radius: 15px;
box-shadow: 0 4px 15px rgba(0,0,0,0.1);
width: 400px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
width: 380px;
text-align: center;
}
h2 {
color: #ff69b4;
margin-bottom: 20px;
}
input[type=text], input[type=password] {
input {
width: 90%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ddd;
border-radius: 8px;
border: 1px solid #ccc;
}
button {
background: linear-gradient(45deg, #ff69b4, #ffa07a);
color: white;
border: none;
padding: 12px 25px;
border-radius: 25px;
color: white;
padding: 10px 20px;
border-radius: 20px;
cursor: pointer;
font-weight: bold;
}
button:hover {
opacity: 0.9;
}
a {
color: #ff69b4;
text-decoration: none;
font-weight: 600;
width: 95%;
}
a:hover {
text-decoration: underline;
}
button:hover { opacity: 0.9; }
.message { color: red; margin-bottom: 10px; }
a { color: #ff69b4; text-decoration: none; }
</style>
</head>
<body>
<div class="container">
<h2>Créer un compte</h2>
<h2>Créer un compte</h2>
<?php if ($message): ?><div class="message"><?= $message ?></div><?php endif; ?>
<form method="POST">
<input type="text" name="username" placeholder="Nom d'utilisateur" required><br>
<input type="email" name="email" placeholder="Email" required><br>
<input type="password" name="password" placeholder="Mot de passe" required><br>
<button type="submit">S'inscrire</button>
</form>
<p>Déjà un compte ? <a href="login.php">Se connecter</a></p>
<p>Déjà inscrit ? <a href="login.php">Connectez-vous</a></p>
</div>
</body>
</html>
<?php include "footer.php"; ?>