fix password problem
This commit is contained in:
+15
-10
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
|
const hashedAdminPassword = "7215d31f702fe2faf2a7df114c6427007bd254740c6b9cbaa2a5505060088929";
|
||||||
|
|
||||||
async function SqlRequest(action, params = {}) {
|
async function SqlRequest(action, params = {}) {
|
||||||
try {
|
try {
|
||||||
@@ -92,23 +92,28 @@ async function joinGameAsAdmin(gameId) {
|
|||||||
// Récupérer le formulaire de admin-login
|
// Récupérer le formulaire de admin-login
|
||||||
const adminLoginForm = document.getElementById('admin-login-form');
|
const adminLoginForm = document.getElementById('admin-login-form');
|
||||||
|
|
||||||
if (adminLoginForm) {
|
|
||||||
adminLoginForm.addEventListener('submit', async function(event) {
|
adminLoginForm.addEventListener('submit', async function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const password = document.getElementById('admin-password').value;
|
// Désactiver le bouton pour éviter les soumissions multiples
|
||||||
|
const password = this.querySelector('input[type="password"]').value;
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
const gameId = urlParams.get('game_id');
|
const gameId = urlParams.get('game_id');
|
||||||
const response = await SqlRequest('adminLogin', {
|
// Vérification du mot de passe
|
||||||
password: password,
|
const hashedInputPassword = CryptoJS.SHA256(password).toString();
|
||||||
game_id: gameId
|
|
||||||
});
|
if (hashedInputPassword !== hashedAdminPassword) {
|
||||||
|
alert("Mot de passe incorrect. Veuillez réessayer.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Requete SQL pour définir l'utilisateur comme admin du jeu
|
||||||
|
const response = await SqlRequest('adminLogin', {game_id: gameId});
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
window.location.href = `admin-game.html?game_id=${gameId}`;
|
window.location.href = `admin-game.html?game_id=${gameId}`; // Redirige vers la page d'administration du jeu
|
||||||
} else {
|
} else {
|
||||||
alert("Identifiants incorrects. Veuillez réessayer.");
|
alert("Erreur lors de la connexion. Veuillez réessayer."); // Affiche une alerte en cas d'erreur
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -227,17 +227,15 @@ switch ($action) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'adminLogin':
|
case 'adminLogin':
|
||||||
$stmt = $pdo->prepare("SELECT * FROM admins WHERE game_id = ? AND password = ?");
|
// On vérifie si l'utilisateur est déjà admin
|
||||||
$stmt->execute([$params['game_id'], $params['password']]);
|
|
||||||
$admin = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
||||||
if ($admin) {
|
|
||||||
$response = ['success' => true];
|
|
||||||
session_start();
|
session_start();
|
||||||
$_SESSION['admin_logged_in'] = true;
|
if (isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in'] === true) {
|
||||||
$_SESSION['game_id'] = $params['game_id'];
|
$response = ['success' => true, 'message' => 'Déjà connecté en tant qu\'admin'];
|
||||||
} else {
|
break;
|
||||||
$response = ['error' => 'Mot de passe incorrect'];
|
|
||||||
}
|
}
|
||||||
|
// On dit que l'utilisateur est admin
|
||||||
|
$_SESSION['admin_logged_in'] = true;
|
||||||
|
$response = ['success' => true, 'message' => 'Connexion admin réussie'];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'is_admin':
|
case 'is_admin':
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Admin Login</h1>
|
<h1>Admin Login</h1>
|
||||||
<form id="adminLoginForm">
|
<form id="admin-login-form">
|
||||||
<label for="adminPassword">Mot de passe administrateur :</label>
|
<label for="adminPassword">Mot de passe administrateur :</label>
|
||||||
<input type="password" id="adminPassword" name="adminPassword" required>
|
<input type="password" id="adminPassword" name="adminPassword" required>
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|||||||
Reference in New Issue
Block a user