connection
This commit is contained in:
60
controleurs/ControleurAuthentification.php
Normal file
60
controleurs/ControleurAuthentification.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user