diff --git a/controller/FrontCtrl.php b/controller/FrontCtrl.php index 8d3836d..06fc99c 100644 --- a/controller/FrontCtrl.php +++ b/controller/FrontCtrl.php @@ -6,13 +6,10 @@ class FrontController private UserModel $ursMdl; private $action_User; - function __construct($ursMdl=new UserModel(), $action_User=[]){ - $this->$ursMdl = $ursMdl; - $this->$action_User = $action_User; + function __construct(){ session_start(); - } - - function handleAction(){ + $ursMdl = new UserModel(); + try{ $user = $this->usrMdl.isUser(); // cette fonction retourne quoi? $action = $_GET['action']; diff --git a/controller/UserCtrl.php b/controller/UserCtrl.php index 46ee343..b2fadbc 100644 --- a/controller/UserCtrl.php +++ b/controller/UserCtrl.php @@ -1,47 +1,49 @@ model = $model; - $this->view = $view; + + public function __construct(Connection $con){ + $this->model = new UserModel(); $this->con = $con; - } - - public function handleAction(){ try{ $action=$_REQUEST['action']; switch($action){ // pas d'action afficher la home page avec toutes les listes - case NULL: - $this->home(); - break; - - // ajouter une liste publique - case 'creer_liste_pub': - $this->newList('private'); - break; + // case NULL: + // $this->home(); + // break; - // ajouter une liste privee - case 'creer_liste_priv': - $this->newList('public'); - break; - - // supprimer une liste - case 'supprimer_liste': - $this->delList(); + // voir les listes privees + case 'voir_liste_priv': + $this->listepriv(); break; + + // // ajouter une liste publique + // case 'creer_liste_pub': + // $this->newList('public'); + // break; - // changer nom de la liste - case 'changer_nom': - $this->changeListName(); - break; + // // ajouter une liste privee + // case 'creer_liste_priv': + // $this->newList('private'); + // break; + + // // supprimer une liste + // case 'supprimer_liste': + // $this->delList(); + // break; + + // // changer nom de la liste + // case 'changer_nom': + // $this->changeListName(); + // break; // ajouter une tache diff --git a/dal/UserGateway.php b/dal/UserGateway.php index d9db4ad..0308978 100644 --- a/dal/UserGateway.php +++ b/dal/UserGateway.php @@ -44,12 +44,11 @@ } public function findUser($login, $mdp){ - $pwrd = password_hash($mdp, PASSWORD_BCRYPT, array("cost" => 12)); - $query = 'SELECT login FROM User WHERE login = :login AND mdp = :mdp'; - $this->con->executeQuery($query, array(':login'=>array($login, PDO::PARAM_STR), - ':mdp'=>array($pwrd, PDO::PARAM_STR))); + $query = 'SELECT mdp FROM User WHERE login = :login'; + $this->con->executeQuery($query, array(':login'=>array($login, PDO::PARAM_STR))); $result = $this->con->getResults(); - return $result; + if(password_verify($mdp, $result[0]['mdp'])) + return $login; } } ?> \ No newline at end of file diff --git a/model/UserModel.php b/model/UserModel.php index 5ed7c9a..d032998 100644 --- a/model/UserModel.php +++ b/model/UserModel.php @@ -4,13 +4,18 @@ private $con; private $gat; - public function __construct(Connection $con) { - $this->con = $con; - $this->gat = new GatUser($con); } + public function __construct(Connection $con) { + $this->con = $con; + $this->gat = new UserGateway($con); + } function connexion($login, $mdp){ - $gat->findUser($login, $mdp); - $_SESSION['login'] = $login; + $result = $this->gat->findUser($login, $mdp); + if (isset($result)) + { + $_SESSION['login'] = $result; + } + echo $_SESSION['login']; } function deconnexion(){ @@ -20,7 +25,7 @@ } function isConnected($login){ //teste rôle dans la session, retourne instance d’objet ou booleen - if (isset($_SESSION['login'])) + if ($_SESSION['login']) { return true; } diff --git a/tests/test.php b/tests/test.php index a55aa07..2a02743 100644 --- a/tests/test.php +++ b/tests/test.php @@ -11,10 +11,10 @@ $t = new Task(5,'tacheNotErr','desc.','urgent','001'); # connection include("credentials.php"); -$con = new Connection('mysql:host=localhost;dbname=phpproject',$user,$pass); +$con = new Connection('mysql:host=localhost;dbname=dbanboudoul', 'anboudoul', 'achanger'); # gateway -$tgt = new TaskGateway($con); +// $tgt = new TaskGateway($con); //$tgt->insert($t); //$tgt->delete('10'); @@ -24,16 +24,16 @@ foreach($tasks as $i) echo $i->get_id()."
"; */ # Test du modele Tache -$mt= new TaskModel($con); +// $mt= new TaskModel($con); //$mt->addTask('3','testIsDone','desc.','urgent','001'); //$mt->modifTask('3','isDone','1'); //$tasks = $mt->getTaskBy('titre','tache1'); -$tasks = $mt->getAllTask(); -foreach($tasks as $i) - echo $i->get_id()."
"; +// $tasks = $mt->getAllTask(); +// foreach($tasks as $i) +// echo $i->get_id()."
"; -$mt->addList('002','todo2','nifranco'); -$mt->modifList('2','nom','22do'); +// $mt->addList('002','todo2','nifranco'); +// $mt->modifList('2','nom','22do'); //mt->supList('2'); /* ------------- @@ -54,11 +54,12 @@ require('../model/UserModel.php'); // Test Modèle User -// $mdl = new UserModel($con); +$mdl = new UserModel($con); // $mdl->ajouter('Anna', 'unmdptrescomplique'); // $mdl->modifLogin('Anna', 'Aeryn'); // $mdl->modifMdp('Aeryn', 'wtfmec'); // $mdl->supprimer('Aeryn'); +$mdl->connexion('Aeryn', 'wtfmec'); ?>