From ee976b8a6e391dd8e98f162dc6310f218bec01be Mon Sep 17 00:00:00 2001 From: BRAMAS Arthur Date: Fri, 10 Oct 2025 10:21:27 +0200 Subject: [PATCH] Authentication works --- controller/AuthController.php | 54 +++++++++++++++++ public/index.php | 62 ++++++++++---------- {_old/utils_inc => utils_inc}/inc_navbar.php | 0 utils_inc/inc_pdo.php | 3 + view/ConnForm.php | 36 ++++++++++++ view/home.php | 14 +++++ 6 files changed, 137 insertions(+), 32 deletions(-) rename {_old/utils_inc => utils_inc}/inc_navbar.php (100%) create mode 100644 utils_inc/inc_pdo.php create mode 100644 view/ConnForm.php create mode 100644 view/home.php diff --git a/controller/AuthController.php b/controller/AuthController.php index e69de29..495e910 100644 --- a/controller/AuthController.php +++ b/controller/AuthController.php @@ -0,0 +1,54 @@ +prepare($textR); + $req->bindParam(":login", $login); + $req->execute(); + + // 2 possibilités : 1 ligne retournée ou 0 ligne retournée + $tabRes = $req->fetchAll(PDO::FETCH_ASSOC); + if (count($tabRes)!=1) { + // pas trouvé => retour au formulaire de co + // die("Erreur de co"); + header("Location:../index.php?message=tekitoa"); + exit(); + } + + // Si on arrive là : login existe (count==1) + if (!password_verify($pass, $tabRes[0]["password"])){ + // die("Erreur de co"); + header("Location:../index.php?message=tekitoa"); + exit(); + } + + $_SESSION["login"] = $login; + $_SESSION["droit"] = $tabRes[0]["droit"]; + + // redirection vers accueil, éventuellement spécifique à l'utilisateur + header("Location:../view/home.php"); + } +} \ No newline at end of file diff --git a/public/index.php b/public/index.php index 910e2a3..05f3c3a 100644 --- a/public/index.php +++ b/public/index.php @@ -1,36 +1,34 @@ + define("BASE_URL","/contribEvo/"); - - - - - - - Connexion - + //index.php?route=maRoute¶m1=truc + // => receive get route - -
-
-
-

Identifiez-vous

-
-
- -
-
-
- -
-
-
- -
-
-
-
- - - \ No newline at end of file + $route = isset($_GET["route"])? $_GET["route"] : null; + + /* + if (isset($_GET["route"])) { + $route = $_GET["route"] + } else { + $route = null; + } + */ + if ($route=="helloworld") { + $ctr = new AuthController(); + $ctr->helloWorld(); + exit(); + } + + if ($route=="displayConnForm") { + $ctr = new AuthController(); + $ctr->displayConnForm(); + exit(); + } + + if ($route=="handleConnForm") { + $ctr = new AuthController(); + $ctr->handleConnForm(); + exit(); + } diff --git a/_old/utils_inc/inc_navbar.php b/utils_inc/inc_navbar.php similarity index 100% rename from _old/utils_inc/inc_navbar.php rename to utils_inc/inc_navbar.php diff --git a/utils_inc/inc_pdo.php b/utils_inc/inc_pdo.php new file mode 100644 index 0000000..471b926 --- /dev/null +++ b/utils_inc/inc_pdo.php @@ -0,0 +1,3 @@ + + + + + + + + + Connexion + + + +
+
+
+

Identifiez-vous

+
+
+ +
+
+
+ +
+
+
+ +
+
+
+
+ + + \ No newline at end of file diff --git a/view/home.php b/view/home.php new file mode 100644 index 0000000..25b9f4a --- /dev/null +++ b/view/home.php @@ -0,0 +1,14 @@ + + + + + + Document + + + + + +

Hello et bienvenue, co OK.

+ + \ No newline at end of file