60 lines
2.2 KiB
PHP
60 lines
2.2 KiB
PHP
<?php
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/tools/dbConnect.php';
|
|
session_start();
|
|
|
|
if (isset($_COOKIE['userData'])) {
|
|
$userDataEncoded = $_COOKIE['userData'];
|
|
$userData = json_decode($userDataEncoded, true); // 'true' pour obtenir un tableau associatif
|
|
|
|
$email = $userData['email'];
|
|
$name = $userData['name'];
|
|
$familyName = $userData['familyName'];
|
|
$role = $userData['role'];
|
|
}
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
$userName = htmlspecialchars($_POST["name"]);
|
|
$userFamilyName = htmlspecialchars($_POST["family_name"]);
|
|
$userEmail = htmlspecialchars($_POST["email"]);
|
|
$userPassword = isset($_POST["password"]) ? htmlspecialchars($_POST["password"]) : "";
|
|
$userUserRole = htmlspecialchars($_POST["role"]);
|
|
$hashedPassword = sha1($userPassword);
|
|
|
|
$query = "SELECT mail FROM user WHERE mail = '$userEmail'";
|
|
$result = mysqli_query($db, $query);
|
|
|
|
$row = mysqli_fetch_assoc($result);
|
|
|
|
if ($row) {
|
|
die("<p>Un utilisateur avec cette adresse mail existe déjà.</p>");
|
|
}
|
|
}
|
|
|
|
if (!$result) {
|
|
die("Erreur lors de l'exécution de la requête.");
|
|
}
|
|
|
|
$editUser = "UPDATE `user` SET `mail`='$userEmail', `name`='$userName', `family_name`='$userFamilyName', `role`='$userUserRole' WHERE `mail`='$userEmail'";
|
|
|
|
$resultEditUser = mysqli_query($db, $editUser);
|
|
if (!$resultEditUser) {
|
|
echo "<p class='text'>Erreur lors de l'exécution de la requête.</p>";
|
|
} else {
|
|
if (mysqli_affected_rows($db) > 0) {
|
|
echo "<p class='text'>Utilisateur créé avec succès. </p>";
|
|
|
|
echo "<p class='text'>Prénom : " . $userName . "</p>";
|
|
echo "<p class='text'>Nom : " . $userFamilyName . "</p>";
|
|
echo "<p class='text'>Adresse mail : " . $userEmail . "</p>";
|
|
echo "<p class='text'>Mot de passe : " . $userPassword . "</p>";
|
|
echo "<p class='text'>Mot de passe hashé : " . $hashedPassword . "</p>";
|
|
echo "<p class='text'>Rôle : " . $userUserRole . "</p>";
|
|
include ($_SERVER['DOCUMENT_ROOT'] . '/tools/discordWebhookRegister.php');
|
|
header("Location: /admin/users/edit?usermail=$userEmail");
|
|
die();
|
|
} else {
|
|
echo "<p class='text'>Aucun utilisateur n\'a été ajouté.</p>";
|
|
}
|
|
}
|
|
|
|
?>
|