From 18dc85491bd0ba00e54efe80e6331cce38a93fb6 Mon Sep 17 00:00:00 2001 From: "nicolas.franco" Date: Sat, 3 Dec 2022 18:57:25 +0100 Subject: [PATCH 1/3] db credentials update --- tests/credentials.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/credentials.php b/tests/credentials.php index 1db9dae..9d5efdf 100644 --- a/tests/credentials.php +++ b/tests/credentials.php @@ -1,4 +1,4 @@ From cfcc627fd79742d601eed3b1e0e4c7e9045ecbd6 Mon Sep 17 00:00:00 2001 From: Anna BOUDOUL Date: Tue, 13 Dec 2022 16:59:57 +0100 Subject: [PATCH 2/3] suite --- controller/FrontCtrl.php | 9 ++---- controller/UserCtrl.php | 62 +++++++++++++++++++++------------------- dal/UserGateway.php | 9 +++--- model/UserModel.php | 17 +++++++---- tests/test.php | 19 ++++++------ 5 files changed, 60 insertions(+), 56 deletions(-) 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'); ?> From 840ec257e18914c7529025a8b8377c03ad9c53ae Mon Sep 17 00:00:00 2001 From: Anna BOUDOUL Date: Tue, 13 Dec 2022 18:49:15 +0100 Subject: [PATCH 3/3] =?UTF-8?q?d=C3=A9but=20user=20controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/ListTask.php | 3 ++- controller/FrontCtrl.php | 4 +-- controller/UserCtrl.php | 57 ++++++++++++++++------------------------ tests/test.php | 8 ++++-- view/liste.php | 14 ++++++++++ 5 files changed, 45 insertions(+), 41 deletions(-) create mode 100644 view/liste.php diff --git a/business/ListTask.php b/business/ListTask.php index 5a2ce29..a2c1789 100644 --- a/business/ListTask.php +++ b/business/ListTask.php @@ -6,11 +6,12 @@ private string $owner; private int $dc; // done counter - function __construct($id, $nom, $owner="", $dc=0) { + function __construct($id, $nom, $owner="", $dc = 0) { $this->id = $id; $this->nom = $nom; $this->taches = []; $this->owner = $owner; + $this->dc = $dc; } diff --git a/controller/FrontCtrl.php b/controller/FrontCtrl.php index 06fc99c..7d278cc 100644 --- a/controller/FrontCtrl.php +++ b/controller/FrontCtrl.php @@ -19,19 +19,17 @@ class FrontController # appel controlleur visiteur avec action connecter require("VisitCtrl.php"); $visitCtrl = new VisitCtrl(); - $visitCtrl.handleAction('connecter'); + $visitCtrl->goconnexion(); } else { # sinon # handle action avec controlleur user require("UserCtrl.php"); $userCtrl = new UserCtrl(); - $userCtrl.handleAction($action); } } else { # sinon forcement action visiteur # appel controlleur visiteur avec l'action require("VisitCtrl.php"); $visitCtrl = new VisitCtrl(); - $visitCtrl.handleAction($action); } } catch (Exception $e){ // verifier si catch bon require("../view/erreur.php"); diff --git a/controller/UserCtrl.php b/controller/UserCtrl.php index b2fadbc..063ae51 100644 --- a/controller/UserCtrl.php +++ b/controller/UserCtrl.php @@ -1,58 +1,45 @@ model = new UserModel(); $this->con = $con; + $this->model = new UserModel($this->con); try{ $action=$_REQUEST['action']; switch($action){ - // pas d'action afficher la home page avec toutes les listes - // case NULL: - // $this->home(); - // break; - + // voir les listes privees case 'voir_liste_priv': - $this->listepriv(); + $this->loadListePriv(); break; - - // // ajouter une liste publique - // case 'creer_liste_pub': - // $this->newList('public'); - // 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 - - // completer tache + // ajouter une liste privee + case 'creer_liste_priv': + $this->newListPrivate(); + break; } } catch(Exception $e) { require("../view/erreur.php"); } } + + public function loadListePriv(){ + $name = "Liste privée"; + $TabList = array(); + // $TabList[] = new ListTask(0, "Projet PHP"); + // $TabList[] = new ListTask(1, "Projet Blazor"); + $TabListPriv = $this->model->getPrivateList(); + require("../view/liste.php"); + } + + public function newListPrivate(){ + $nom=$_POST['listeNom']; + insertL(new ListTask(0, $nom, $_SESSION['login'])); + } } ?> diff --git a/tests/test.php b/tests/test.php index 2a02743..7927c18 100644 --- a/tests/test.php +++ b/tests/test.php @@ -42,6 +42,7 @@ TEST ANNA require('../dal/UserGateway.php'); require('../model/UserModel.php'); +require('../controller/UserCtrl.php'); // Test Gateway User @@ -54,12 +55,15 @@ 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'); +// $mdl->connexion('Aeryn', 'wtfmec'); + +$usrctrl = new UserCtrl($con); +$usrctrl->loadListePriv(); ?> diff --git a/view/liste.php b/view/liste.php new file mode 100644 index 0000000..d11235d --- /dev/null +++ b/view/liste.php @@ -0,0 +1,14 @@ + + + + '; + echo '

'.$name.'

'; + echo '
'; + foreach($TabList as $liste){ + echo ''; + } + echo '
'; +?> \ No newline at end of file