2024-06-11 10:56:40 +02:00
|
|
|
<?php
|
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/tools/dbConnect.php';
|
2024-06-11 22:49:01 +02:00
|
|
|
session_start();
|
2024-06-11 10:56:40 +02:00
|
|
|
|
2024-06-11 22:49:01 +02:00
|
|
|
if (isset($_COOKIE['userData'])) {
|
|
|
|
$userDataEncoded = $_COOKIE['userData'];
|
2024-06-16 17:17:55 +02:00
|
|
|
$userData = json_decode($userDataEncoded, true);
|
2024-06-11 22:49:01 +02:00
|
|
|
|
|
|
|
$email = $userData['email'];
|
|
|
|
$oldEmail = $userData['email'];
|
|
|
|
$name = $userData['name'];
|
|
|
|
$familyName = $userData['familyName'];
|
|
|
|
$role = $userData['role'];
|
|
|
|
}
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
|
|
$name = htmlspecialchars($_POST["name"]);
|
|
|
|
$familyName = htmlspecialchars($_POST["family_name"]);
|
|
|
|
$email = htmlspecialchars($_POST["email"]);
|
|
|
|
$password = htmlspecialchars($_POST["password"]);
|
|
|
|
$hashedPassword = sha1($password);
|
2024-06-11 10:56:40 +02:00
|
|
|
|
|
|
|
|
2024-06-11 22:49:01 +02:00
|
|
|
|
2024-06-16 17:17:55 +02:00
|
|
|
$updateUser = "UPDATE `user` SET `name`='$name',`family_name`='$familyName',`password`='$hashedPassword' WHERE mail = '$oldEmail'";
|
2024-06-11 22:49:01 +02:00
|
|
|
$resultUpdateUser = mysqli_query($db, $updateUser);
|
|
|
|
if ($resultUpdateUser) {
|
|
|
|
setcookie("userData", "", time() - 3600, "/");
|
|
|
|
$role = $userData['role'];
|
|
|
|
$userData = array(
|
|
|
|
"email" => $email,
|
|
|
|
"name" => $name,
|
|
|
|
"familyName" => $familyName,
|
|
|
|
"role" => $role,
|
|
|
|
);
|
|
|
|
$userDataEncoded = json_encode($userData);
|
|
|
|
setcookie("userData", $userDataEncoded, time() + 3600, "/");
|
|
|
|
echo "<p class='text'>Utilisateur mis à jour avec succès. </p>";
|
|
|
|
header("Location: /account/profile?result=updatesuccess");
|
|
|
|
} else {
|
|
|
|
echo "<p class='text'>Erreur lors de l'exécution de la requête.</p>";
|
|
|
|
header("Location: /account/profile?result=updatefailed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-16 17:17:55 +02:00
|
|
|
?>
|