99 lines
2.5 KiB
PHP
99 lines
2.5 KiB
PHP
<?php
|
|
session_start();
|
|
require_once "config.php";
|
|
include "header.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
|
|
|
|
// Vérifier si le nom d'utilisateur existe déjà
|
|
$stmt = $pdo->prepare("SELECT id FROM utilisateurs WHERE username = ?");
|
|
$stmt->execute([$username]);
|
|
|
|
if ($stmt->rowCount() > 0) {
|
|
echo "<p style='color:red;text-align:center;'>⚠️ Ce nom d'utilisateur existe déjà.</p>";
|
|
} 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>";
|
|
}
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Inscription - Mini CMS</title>
|
|
<style>
|
|
body {
|
|
background: linear-gradient(135deg, #ffb6c1, #ffa07a);
|
|
font-family: 'Poppins', sans-serif;
|
|
margin: 0;
|
|
height: 100vh;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
}
|
|
.container {
|
|
background: white;
|
|
padding: 40px;
|
|
border-radius: 15px;
|
|
box-shadow: 0 4px 15px rgba(0,0,0,0.1);
|
|
width: 400px;
|
|
text-align: center;
|
|
}
|
|
h2 {
|
|
color: #ff69b4;
|
|
margin-bottom: 20px;
|
|
}
|
|
input[type=text], input[type=password] {
|
|
width: 90%;
|
|
padding: 10px;
|
|
margin: 10px 0;
|
|
border-radius: 8px;
|
|
border: 1px solid #ccc;
|
|
}
|
|
button {
|
|
background: linear-gradient(45deg, #ff69b4, #ffa07a);
|
|
color: white;
|
|
border: none;
|
|
padding: 12px 25px;
|
|
border-radius: 25px;
|
|
cursor: pointer;
|
|
font-weight: bold;
|
|
}
|
|
button:hover {
|
|
opacity: 0.9;
|
|
}
|
|
a {
|
|
color: #ff69b4;
|
|
text-decoration: none;
|
|
font-weight: 600;
|
|
}
|
|
a:hover {
|
|
text-decoration: underline;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h2>Créer un compte</h2>
|
|
<form method="POST">
|
|
<input type="text" name="username" placeholder="Nom d'utilisateur" 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>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
|
|
<?php include "footer.php"; ?>
|
|
|