Files
Mise_en_place_mvc/controleurs/ControleurAuthentification.php
2025-10-10 11:15:38 +02:00

60 lines
2.5 KiB
PHP

<?php
Class ControleurAuthentification{
public function coucou(){
echo "coucou!";
}
public function afficherFromCo(){
include __DIR__."/../vues/VueFromCo.php";
}
public function traiterFromCo($cnx,$Login,$password){
var_dump($_POST);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!empty($Login) && !empty($password)) {
try {
$stmt = $cnx->prepare("SELECT M.nom, M.Password, M.droit_id, D.LibDroit, M.id
FROM Membre M
INNER JOIN Droit D ON M.droit_id = D.idDroit
WHERE M.nom = :Login");
$stmt->bindParam(':Login', $Login, PDO::PARAM_STR);
$stmt->execute();
$user = $stmt->fetch(PDO::FETCH_ASSOC);
if ($user && password_verify($password, $user['Password'])) {
$_SESSION['user'] = [
'idD' => $user['droit_id'],
'idM' => $user['id'],
'Login' => $user['nom'],
'role' => $user['LibDroit']
];
// Redirection selon le rôle
if ($user['LibDroit'] === 'responsable') {
$message = urlencode("Connexion réussie. Bienvenue responsable : " . htmlspecialchars($user['nom']) . "!");
header("Location: index.php?route=coucou&message=$message");
} elseif ($user['LibDroit'] === 'dev') {
$message = urlencode(htmlspecialchars($user['nom']) );
header("location: index.php?route=coucou&message=$message");
} else {
$_SESSION['erreur'] = "Rôle inconnu";
header("location:index.php?route=afficherFromCo");
exit();
}
} else {
$_SESSION['erreur'] = "Identifiants incorrects";
header("location: index.php?route=afficherFromCo");
exit();
}
} catch (Exception $e) {
$_SESSION['erreur'] = "Erreur : " . $e->getMessage();
header("location :index.php?route=afficherFromCo");
exit();
}
}
}
}
}