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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
31
public/index.php
Normal file
31
public/index.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once __DIR__."/../controleurs/ControleurAuthentification.php";
|
||||
// index.php?route=maRoute¶m1=truc
|
||||
// => route reçue en get
|
||||
define("BASE_URL","/contribsavantrouteur/");
|
||||
$route = isset($_GET["route"])? $_GET["route"] : null;
|
||||
$pdo = new PDO("mysql:host=mysqlsrv;dbname=contrib",
|
||||
"contrib_root",
|
||||
"123abc");
|
||||
|
||||
if ($route=="coucou"){
|
||||
$ctr = new ControleurAuthentification;
|
||||
$ctr->coucou();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($route=="afficherFromCo"){
|
||||
$ctr = new ControleurAuthentification;
|
||||
$ctr->afficherFromCo();
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($route=="traiterFromCo"){
|
||||
echo "Je suis là";
|
||||
$ctr = new ControleurAuthentification;
|
||||
$ctr->traiterFromCo($pdo,$_POST["login"],$_POST["pass"]);
|
||||
exit();
|
||||
}
|
||||
|
||||
echo "Route inconnue";
|
@@ -6,7 +6,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link href="css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="<?=BASE_URL?>css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="css/styles.css" rel="stylesheet">
|
||||
<title>Connexion</title>
|
||||
</head>
|
||||
@@ -14,7 +14,7 @@
|
||||
<body class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-4">
|
||||
<form id="formLogin" action="traitements/traiterAuthentification.php" method="post">
|
||||
<form id="formLogin" action="index.php?route=traiterFromCo" method="post">
|
||||
<h3 class="text-center">Identifiez-vous</h3>
|
||||
<div class="form-group">
|
||||
<label for="id">Login :</label><br>
|
Reference in New Issue
Block a user