diff --git a/controller/FrontCtrl.php b/controller/FrontCtrl.php index 77f18e8..12bfd23 100644 --- a/controller/FrontCtrl.php +++ b/controller/FrontCtrl.php @@ -14,7 +14,7 @@ class FrontCtrl $this->TMessage = $TMessage; $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(); @@ -24,12 +24,12 @@ class FrontCtrl if(!$this->isUser){ # si pas conncter # appel controlleur visiteur avec action connecter require("VisitorCtrl.php"); - $visitCtrl = new VisitorCtrl($con, $this->TabVues, $this->TMessage); + $visitCtrl = new VisitorCtrl($con, $this->TabVues, $this->TMessage, $this->isUser); $visitCtrl->goconnexion(); } 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 aece6f5..e22a11d 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 1623c0f..d82f1f4 100644 --- a/controller/VisitorCtrl.php +++ b/controller/VisitorCtrl.php @@ -20,7 +20,7 @@ class VisitorCtrl $action = $_REQUEST['action']; else $action = null; - + switch($action){ case null: $this->loadHome(); @@ -95,7 +95,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"]); } @@ -110,7 +119,7 @@ class VisitorCtrl } function connection(){ - $this->userModel->connexion($user,$mdp); + $this->userModel->connexion($_POST['username'],$_POST['password']); $this->loadHome(); } @@ -120,7 +129,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..4bee498 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)) + + 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 diff --git a/view/connection.php b/view/connection.php index 1af11f7..05f19b9 100644 --- a/view/connection.php +++ b/view/connection.php @@ -48,21 +48,22 @@