From 93020c97e4bff908c17d8f3677a2f63d243c6e9e Mon Sep 17 00:00:00 2001 From: "nicolas.franco" Date: Fri, 23 Dec 2022 13:00:18 +0100 Subject: [PATCH 1/2] correction findUser --- controller/VisitorCtrl.php | 7 ++++--- dal/UserGateway.php | 4 ++-- view/connection.php | 9 +++++---- view/newTask.php | 10 +++++----- view/register.php | 9 +++++---- 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/controller/VisitorCtrl.php b/controller/VisitorCtrl.php index 68de0e9..8c3d756 100644 --- a/controller/VisitorCtrl.php +++ b/controller/VisitorCtrl.php @@ -19,7 +19,7 @@ class VisitorCtrl $action = $_REQUEST['action']; else $action = null; - + switch($action){ case null: $this->loadHome(); @@ -99,7 +99,7 @@ class VisitorCtrl } function connection(){ - $this->userModel->connexion($user,$mdp); + $this->userModel->connexion($_POST['username'],$_POST['password']); $this->loadHome(); } @@ -109,7 +109,8 @@ class VisitorCtrl } function register(){ - $this->userModel->ajouter($user,$mdp); + $this->userModel->ajouter($_POST['username'],$_POST['password']); + $this->go_connection(); } function go_list(){ diff --git a/dal/UserGateway.php b/dal/UserGateway.php index 9046375..e9573ed 100644 --- a/dal/UserGateway.php +++ b/dal/UserGateway.php @@ -47,8 +47,8 @@ $query = 'SELECT mdp FROM User WHERE login = :login'; $this->con->executeQuery($query, array(':login'=>array($login, PDO::PARAM_STR))); $result = $this->con->getResults(); - $hash = password_hash($result[0]['mdp'], PASSWORD_BCRYPT, array("cost" => 12)); - if(password_verify($mdp, $hash)) + echo var_dump($result[0][0])."
"; + if(password_verify($mdp, $result[0][0])) return $login; } } diff --git a/view/connection.php b/view/connection.php index 5033d37..e1c61ef 100644 --- a/view/connection.php +++ b/view/connection.php @@ -48,21 +48,22 @@

Welcome back!

-
+
- +
- +
- + +
diff --git a/view/newTask.php b/view/newTask.php index fa2dbf0..3b52f0f 100644 --- a/view/newTask.php +++ b/view/newTask.php @@ -54,6 +54,11 @@ +
+ + +
+
@@ -69,11 +74,6 @@
-
- - -
- diff --git a/view/register.php b/view/register.php index 91f2d71..3849011 100644 --- a/view/register.php +++ b/view/register.php @@ -48,21 +48,22 @@

Make private lists with a personnal account

-
+
- +
- +
- + +
From a40e051ffbe60839c1769675979a22a3d1e2ff5e Mon Sep 17 00:00:00 2001 From: "nicolas.franco" Date: Fri, 23 Dec 2022 13:32:03 +0100 Subject: [PATCH 2/2] log out works (made some changes on controllers and gateway deconnection function) --- controller/FrontCtrl.php | 8 ++++---- controller/UserCtrl.php | 6 +++--- controller/VisitorCtrl.php | 11 ++++++++++- dal/UserGateway.php | 2 +- model/UserModel.php | 2 +- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/controller/FrontCtrl.php b/controller/FrontCtrl.php index 1a4defa..e81ab76 100644 --- a/controller/FrontCtrl.php +++ b/controller/FrontCtrl.php @@ -13,7 +13,7 @@ class FrontCtrl session_start(); $this->TabVues = $TabVues; $this->usrMdl = new UserModel($con); - $this->action_User = array('deconnexion','loadListePriv','newListPrivate'); + $this->action_User = array('deconnecter','loadListePriv','newListPrivate'); try{ $this->isUser = $this->usrMdl->isConnected(); @@ -23,12 +23,12 @@ class FrontCtrl if(!$this->isUser){ # si pas conncter # appel controlleur visiteur avec action connecter require("VisitorCtrl.php"); - $visitCtrl = new VisitorCtrl($con, $this->TabVues); - $visitCtrl->goconnexion(); + $visitCtrl = new VisitorCtrl($con, $this->TabVues,$this->isUser); + $visitCtrl->go_connection(); } else { # sinon # handle action avec controlleur user require("UserCtrl.php"); - $userCtrl = new UserCtrl(); + $userCtrl = new UserCtrl($con, $this->TabVues); } } else { # sinon forcement action visiteur diff --git a/controller/UserCtrl.php b/controller/UserCtrl.php index f7150f9..3419cac 100644 --- a/controller/UserCtrl.php +++ b/controller/UserCtrl.php @@ -1,5 +1,5 @@ deconnexion(); - loadHome(); + $this->userModel->deconnexion(); + header("Location:index.php"); } } ?> diff --git a/controller/VisitorCtrl.php b/controller/VisitorCtrl.php index 8c3d756..8105396 100644 --- a/controller/VisitorCtrl.php +++ b/controller/VisitorCtrl.php @@ -89,7 +89,16 @@ class VisitorCtrl } function loadHome(){ $public_lists = $this->taskModel->loadPublicLists(); - $user = $this->isUser; + + # le if suivant est nécéssaire dans le cas ou l'action + # connection a été appeller. Dans ce cas, loadHome doit + # prendre en compte le user qui vient d'être ajouter a + # $_SESSION['login'] + if(isset($_SESSION['login']) && $_SESSION['login'] != "") + $user = $_SESSION['login']; + else + $user = $this->isUser; + require($this->TabVues["home"]); } diff --git a/dal/UserGateway.php b/dal/UserGateway.php index e9573ed..4bee498 100644 --- a/dal/UserGateway.php +++ b/dal/UserGateway.php @@ -47,7 +47,7 @@ $query = 'SELECT mdp FROM User WHERE login = :login'; $this->con->executeQuery($query, array(':login'=>array($login, PDO::PARAM_STR))); $result = $this->con->getResults(); - echo var_dump($result[0][0])."
"; + if(password_verify($mdp, $result[0][0])) return $login; } diff --git a/model/UserModel.php b/model/UserModel.php index 5cf0fad..3f12220 100644 --- a/model/UserModel.php +++ b/model/UserModel.php @@ -16,6 +16,7 @@ Validation::val_form_texte($login, $TMessage); Validation::val_form_mdp($mdp, $TMessage); $result = $this->gat->findUser($login, $mdp); + if(!isset($result)) echo 'not set works'; else { @@ -26,7 +27,6 @@ function deconnexion(){ session_unset(); session_destroy(); - $_SESSION = array(); } function isConnected(){ //teste rôle dans la session, retourne instance d’objet ou booleen