2024-06-09 17:07:43 +02:00
|
|
|
<?php
|
|
|
|
require_once ($_SERVER['DOCUMENT_ROOT'] . '/tools/dbConnect.php');
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
|
|
$email = htmlspecialchars($_POST["email"]);
|
|
|
|
$password = htmlspecialchars($_POST["password"]);
|
|
|
|
}
|
2024-06-14 17:31:37 +02:00
|
|
|
if (isset($_COOKIE['userData'])) {
|
|
|
|
header("Location: /account/profile");
|
|
|
|
}
|
2024-06-10 23:23:51 +02:00
|
|
|
$hashedPassword = sha1($password);
|
2024-06-14 17:31:37 +02:00
|
|
|
$stmt = mysqli_prepare($db, "SELECT * FROM user WHERE mail = ? AND password = ?");
|
|
|
|
mysqli_stmt_bind_param($stmt, 'ss', $email, $hashedPassword);
|
|
|
|
$result = mysqli_stmt_execute($stmt);
|
|
|
|
$result = $stmt->get_result();
|
2024-06-10 23:23:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
if (!$result) {
|
2024-06-14 17:31:37 +02:00
|
|
|
die('Erreur de requête : ' . mysqli_error($db));
|
2024-06-10 23:23:51 +02:00
|
|
|
} else {
|
2024-06-14 17:31:37 +02:00
|
|
|
if (mysqli_num_rows($result) == 0) {
|
|
|
|
header("Location: /account/login?res=login-failed");
|
|
|
|
die();
|
2024-06-10 23:23:51 +02:00
|
|
|
} else {
|
2024-06-14 17:31:37 +02:00
|
|
|
// Requête pour récupérer les informations de l'utilisateur
|
|
|
|
$query = "SELECT name, family_name, role FROM user WHERE mail = '$email'";
|
|
|
|
$result = mysqli_query($db, $query);
|
|
|
|
|
|
|
|
if (!$result) {
|
|
|
|
die('Erreur de requête : ' . mysqli_error($db));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Récupération des données
|
|
|
|
if ($row = mysqli_fetch_assoc($result)) {
|
|
|
|
$nameFetched = $row['name'];
|
|
|
|
$familyNameFetched = $row['family_name'];
|
|
|
|
$roleFetched = $row['role'];
|
|
|
|
} else {
|
|
|
|
echo "Aucun utilisateur trouvé avec cet email.";
|
|
|
|
}
|
|
|
|
// Mise en forme dans un format .JSON et création du cookie.
|
|
|
|
$userData = array(
|
|
|
|
"email" => $email,
|
|
|
|
"name" => $nameFetched,
|
|
|
|
"familyName" => $familyNameFetched,
|
|
|
|
"role" => $roleFetched
|
|
|
|
);
|
|
|
|
$userDataEncoded = json_encode($userData);
|
|
|
|
setcookie("userData", $userDataEncoded, time() + 3600, "/");
|
|
|
|
|
|
|
|
// Utilistation d'un Webhook Discord pour notifier l'administrateur de la
|
|
|
|
//connexion des utilisateurs [fork de : https://stackoverflow.com/a/73547248]
|
|
|
|
|
2024-06-14 17:33:40 +02:00
|
|
|
include ($_SERVER['DOCUMENT_ROOT'] . '/tools/discordWebhookLogin.php');
|
2024-06-14 17:31:37 +02:00
|
|
|
|
|
|
|
header("Location: /?res=login-succeeded");
|
|
|
|
die();
|
2024-06-10 23:23:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|