diff --git a/config/Validation.php b/config/Validation.php index 91bbadc..2479027 100644 --- a/config/Validation.php +++ b/config/Validation.php @@ -62,7 +62,7 @@ } static function clear_string($champ){ - return filter_var($champ, FILTER_SANITIZE_SPECIAL_CHARS); + return filter_var($champ, FILTER_SANITIZE_STRING); } } diff --git a/config/config.php b/config/config.php index f6edb98..d357c9c 100644 --- a/config/config.php +++ b/config/config.php @@ -8,22 +8,12 @@ $bd['user'] = "root"; $bd['pswd'] = "root"; //Vues $vues['acceuil']='vues/acceuil.php'; -$vues['erreur']='vues/erreur.php'; $vues['connection']='vues/connection.php'; $vues['inscription']='vues/inscription.php'; -$vues['profile']='vues/profile.php'; $vues['listesPrivees']='vues/listesPrivees.php'; $vues['creationListe']='vues/creationListe.php'; $vues['infosListe']='vues/infosListe.php'; $vues['creationTache']='vues/creationTache.php'; -// Styles -$styles['commun']='styles/commonStyles.css'; -$styles['acceuil']='styles/acceuilStyles.css'; -$styles['connection']='styles/connectionStyles.css'; -$styles['listesPv']="styles/privateListsStyles.css"; - -// Assets -$assets['logo']='assets/logo.png'; ?> \ No newline at end of file diff --git a/controleurs/ControleurUtilisateur.php b/controleurs/ControleurUtilisateur.php index 2a7ae48..bada6bc 100644 --- a/controleurs/ControleurUtilisateur.php +++ b/controleurs/ControleurUtilisateur.php @@ -20,8 +20,6 @@ class ControleurUtilisateur{ } } - - function creerListePv($arrayErrorViews){ global $rep, $vues, $dataView; //recupérer les valeurs du formulaire @@ -35,14 +33,14 @@ class ControleurUtilisateur{ // appelle à la methode du modèle if($privee == true){ try{ - UserModel::creerListePv($nomListe,$_SESSION['login']); + ListeModel::creerListePv($nomListe,$_SESSION['login']); } catch (PDOException $e){ $dataView[]="Erreur inatendue"; require($rep.$vues['erreur']); } }else{ try{ - VisitorModel::creerListe($nomListe); + ListeModel::creerListe($nomListe); } catch (PDOException $e){ $dataView[]="Erreur inatendue"; require($rep.$vues['erreur']); @@ -52,7 +50,7 @@ class ControleurUtilisateur{ function accessPrivateLists($arrayErrorViews){ global $rep, $vues, $dataView; - $model = new UserModel(); + $model = new ListeModel(); $dataView = $model->pullListesPrivees($_SESSION['login']); require($rep.$vues['listesPrivees']); } diff --git a/controleurs/ControleurVisiteur.php b/controleurs/ControleurVisiteur.php index b2058a4..40274c6 100644 --- a/controleurs/ControleurVisiteur.php +++ b/controleurs/ControleurVisiteur.php @@ -75,7 +75,7 @@ class ControleurVisiteur { public function reinit(){ global $rep,$vues,$dataView,$styles; - $model = new VisiteurModel(); + $model = new ListeModel(); $dataView = $model->pullPublicLists(); require($rep.$vues['acceuil']); @@ -93,7 +93,7 @@ class ControleurVisiteur { global $rep,$vues,$dataView; $nom=$_POST['name']; $idListe=$_POST['liste']; - $model = new ListeModel(); + $model = new TacheModel(); $model->addTache($nom,$idListe); $_REQUEST['action']="accessListInfos"; $this->accessListInfos($arrayErrorViews); @@ -102,7 +102,7 @@ class ControleurVisiteur { public function delTache($arrayErrorViews){ global $rep,$vues,$dataView; $idTache=$_POST['tache']; - $model= new ListeModel(); + $model= new TacheModel(); $model->delTache($idTache); $_REQUEST['action']="accessListInfos"; $this->accessListInfos($arrayErrorViews); @@ -111,7 +111,7 @@ class ControleurVisiteur { public function changeCompletedTache($arrayErrorViews){ global $rep,$vues,$dataView; $idTache=$_POST['tache']; - $model = new ListeModel(); + $model = new TacheModel(); $model->changeCompletedTache($idTache); $_REQUEST['action']="accessListInfos"; $this->accessListInfos($arrayErrorViews); @@ -125,7 +125,7 @@ class ControleurVisiteur { if(!empty($vues_erreur)){ require($rep.$vues['connection']); } - $model= new VisiteurModel(); + $model= new UserModel(); if($model->existUser($usrname)){ if(password_verify($pwd,$model->getHashedPassword($usrname))){ $model->connexion($usrname); @@ -148,7 +148,7 @@ class ControleurVisiteur { $usrname=$_POST['username']; $pwd=$_POST['password']; $confirm=$_POST['confirmpassword']; - $model = new VisiteurModel(); + $model = new UserModel(); $vues_erreur=Validation::val_inscription($usrname,$pwd,$confirm,$vues_erreur); if($model->existUser($usrname)){ $vues_erreur[]="Username already taken"; @@ -162,7 +162,7 @@ class ControleurVisiteur { } $_REQUEST['action']=null; - new ControleurVisiteur(); + $this->reinit(); } public function creerListe(array $vues_erreur){ @@ -189,17 +189,6 @@ class ControleurVisiteur { $_REQUEST['action']=null; $this->reinit(); } - - public function creerTache(array $vues_erreur){ - global $rep, $vues; - require($rep.$vues['creerTache']); - - $intitule = $_POST['intitule']; - $vues_erreur=Validation::val_intitule($intitule, $vues_erreur); - - $model = new ListeModel(); - $model->creerTache(); - } } ?> \ No newline at end of file diff --git a/modeles/Gateways/UserGateway.php b/modeles/Gateways/UserGateway.php index 2c84c61..994bcb3 100644 --- a/modeles/Gateways/UserGateway.php +++ b/modeles/Gateways/UserGateway.php @@ -44,71 +44,6 @@ class UserGateway { return true; } - function delUtilisateur(int $id){ - if(!empty($id)){ - try{ - $co = $this->co; - - $query = "DELETE FROM Utilisateur WHERE id=:id"; - - $co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR))); - } - catch(PDOException $Exception){ - echo 'erreur'; - echo $Exception->getMessage(); - } - } - } - - function putUtilisateur(Utilisateur $usr){ - if(!empty($usr.getId()) && !empty($usr.getNom()) && empty($usr.getPassword())){ - try{ - $co = $this->co; - - $updateQuery = "UPDATE Utilisateur SET id=:id AND nom=:nom AND pwd=:pwd"; - $deleteQuery = "DELETE FROM HasList WHERE user=:id AND liste=:liste"; - $insertQuery = "INSERT INTO HasList VALUES (:id, :liste)"; - - $co->executeQuery($updateQuery, array(':id' => array($usr.getId(), PDO::PARAM_STR), ':nom' => array($usr.getNom(), PDO::PARAM_STR), ':pwd' => array($usr.getPassword(), PDO::PARAM_STR))); - foreach($usr.getListListe() as $l){ - $co->executeQuery($deleteQuery, array(':id' => array($usr.getId(), PDO::PARAM_STR), ':liste' => array($l, PDO::PARAM_STR))); - $co->executeQuery($insertQuery, array(':id' => array($usr.getId(), PDO::PARAM_STR), ':liste' => array($l, PDO::PARAM_STR))); - } - - } - - catch(PDOException $Excception){ - echo 'erreur'; - echo $Excception->getMesage(); - } - } - } - - function getUtilisateurById(int $id) : Utilisateur { - $usr = null; - if(!empty($id)){ - try{ - $co = $this->co; - - $query = "SELECT * FROM Utilisateur WHERE id=:id"; - - $co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR))); - - $results = $co->getResults(); - - foreach($results as $row){ - $usr = new Utilisateur($row['id'], $row['nom'], $row['pwd']); - } - } - catch(PDOException $Exception){ - echo 'erreur'; - echo $Exception->getMessage(); - } - - } - return $usr; - } - function getUtilisateurbyName(string $nom) : ?Utilisateur { $usr = null; $tabList= null; diff --git a/modeles/Modele/ListeModel.php b/modeles/Modele/ListeModel.php index ca5acfe..34594e7 100644 --- a/modeles/Modele/ListeModel.php +++ b/modeles/Modele/ListeModel.php @@ -1,7 +1,7 @@ listgw = new ListeGateway($co); } + public function get_gtwListe(){ + return $this->listgw; + } + function creerListe(string $nom, $private){ if(isset($_SESSION['login'])){ if($private!=null){ - $this->listgw->creerListe($nom,$_SESSION['login']); + $this->get_gtwListe()->creerListe($nom,$_SESSION['login']); }else{ - $this->listgw->creerListe($nom,null); + $this->get_gtwListe()->creerListe($nom,null); } }else{ - $this->listgw->creerListe($nom,null); + $this->get_gtwListe()->creerListe($nom,null); } } - function pullListById(int $idListe){ - return $this->listgw->getById($idListe); + function creerListePv($nom,$idCeator){ + $this->get_gtwListe()->creerListe($nom,$idCreator); } - function addTache(string $intitule, int $idListe ){ - $this->listgw->creerTache($intitule,$idListe); + public function pullPublicLists(){ + return $this->get_gtwListe()->getPublicLists(); } - function delTache(int $idTache){ - $this->listgw->delTache($idTache); + function pullListesPrivees($nom){ + $listes=$this->get_gtwListe()->getByCreator($nom); + return $listes; } - function changeCompletedTache(int $idTache){ - $complete=$this->listgw->getTacheById($idTache); - $this->listgw->updateTache($idTache,$complete); + function pullListById(int $idListe){ + return $this->get_gtwListe()->getById($idListe); } function delListe(int $idListe){ - $this->listgw->delListe($idListe); + $this->get_gtwListe()->delListe($idListe); } } diff --git a/modeles/Modele/TacheModel.php b/modeles/Modele/TacheModel.php new file mode 100644 index 0000000..ceeac4e --- /dev/null +++ b/modeles/Modele/TacheModel.php @@ -0,0 +1,32 @@ +gwList = new ListeGateway($co); + } + + public function get_gwList(){ + return $this->gwList; + } + + function addTache(string $intitule, int $idListe ){ + $this->get_gwList()->creerTache($intitule,$idListe); + } + + function delTache(int $idTache){ + $this->get_gwList()->delTache($idTache); + } + + function changeCompletedTache(int $idTache){ + $complete=$this->get_gwList()->getTacheById($idTache); + $this->get_gwList()->updateTache($idTache,$complete); + } + + + } + +?> \ No newline at end of file diff --git a/modeles/Modele/UserModel.php b/modeles/Modele/UserModel.php index d77b792..0eb0a1d 100644 --- a/modeles/Modele/UserModel.php +++ b/modeles/Modele/UserModel.php @@ -1,14 +1,16 @@ usergw = new UserGateway($co); - $this->listgw = new ListeGateway($co); + } + + public function get_UserGw(){ + return $this->usergw; } function deconnection(){ @@ -17,22 +19,32 @@ class UserModel{ $_SESSION = array(); } - function creerListePv($nom,$idCeator){ - $this->listgw->creerListe($nom,$idCreator); + public function getHashedPassword(string $usr){ + return $this->get_UserGw()->getHashedPassword($usr); } - function desinscription($login){ - $this->usergw->delUtilisateur($login); + public function existUser(string $usr):bool{ + if($this->get_UserGw()->getUtilisateurNom($usr) != null){ + return true; + } + return false; } - function changerPassword($newPassword){ - $this->usergw->putPassword($newPassword); + public function connexion($login){ + $_SESSION['role'] = 'Utilisateur'; + $_SESSION['login'] = $login; } - function pullListesPrivees($nom){ - $listes=$this->listgw->getByCreator($nom); - return $listes; + + public function inscription($login, $mdp){ + $result=$this->get_UserGw()->creerUtilisateur($login, $mdp); + if ($result ==true){ + $_SESSION['role'] = 'Utilisateur'; + $_SESSION['login'] = $login; + } } + + } ?> \ No newline at end of file diff --git a/modeles/Modele/VisiteurModel.php b/modeles/Modele/VisiteurModel.php deleted file mode 100644 index d1bad16..0000000 --- a/modeles/Modele/VisiteurModel.php +++ /dev/null @@ -1,51 +0,0 @@ -gtwUsr = new UserGateway($co); - $this->gtwListe = new ListeGateway($co); - } - - public function getHashedPassword(string $usr){ - return $this->gtwUsr->getHashedPassword($usr); - } - - public function existUser(string $usr):bool{ - if($this->gtwUsr->getUtilisateurNom($usr) != null){ - return true; - } - return false; - } - - public function connexion($login){ - $_SESSION['role'] = 'Utilisateur'; - $_SESSION['login'] = $login; - } - - public function pullPublicLists(){ - return $this->gtwListe->getPublicLists(); - } - - public function inscription($login, $mdp){ - $result=$this->gtwUsr->creerUtilisateur($login, $mdp); - if ($result ==true){ - $_SESSION['role'] = 'Utilisateur'; - $_SESSION['login'] = $login; - } - } - - public function supprListe($id) { - $this->get_gtwListe()->delListe($id); - } - - public function creerTache(string $intitule){ - $this->get_gtwListe()->creerTache($intitule); - } - } - -?> \ No newline at end of file diff --git a/vues/creationListe.php b/vues/creationListe.php index 7b93b2c..6c55190 100644 --- a/vues/creationListe.php +++ b/vues/creationListe.php @@ -2,7 +2,7 @@ creationListe - + @@ -26,6 +26,12 @@ '; } ?> +
+ '.$vues_erreur[0].''; + } + ?> diff --git a/vues/creationTache.php b/vues/creationTache.php index dfdc945..25554e5 100644 --- a/vues/creationTache.php +++ b/vues/creationTache.php @@ -2,7 +2,7 @@ creationTache - + @@ -17,6 +17,14 @@

Name of the task

+ +
+ '.$vues_erreur[0].''; + } + ?> + diff --git a/vues/erreur.php b/vues/erreur.php deleted file mode 100644 index d3a6385..0000000 --- a/vues/erreur.php +++ /dev/null @@ -1,17 +0,0 @@ - - - -
-

Error!

- - - -
- - \ No newline at end of file