From 061aa6ed32d6917b674c186a1dd53b9466c0cb87 Mon Sep 17 00:00:00 2001 From: majean5 Date: Wed, 7 Dec 2022 15:51:42 +0100 Subject: [PATCH] Nouvelles classes et corrections validation, controleurVisiteur, VisiteurModel corrections --- config/Validation.php | 20 ++++++++ controleurs/ControleurVisiteur.php | 75 +++++++++++++++++++++++++++++- modeles/Gateways/ListeGateway.php | 39 ++++++++++++++-- modeles/Gateways/UserGateway.php | 38 ++------------- modeles/Modèle/UserModel | 9 ++++ modeles/Modèle/VisiteurModel | 48 +++++++++++++++++++ modeles/Métier/Tache.php | 8 +--- views/styles/commonStyles.css | 26 ----------- vues/connection.php | 4 +- vues/inscription.php | 4 +- 10 files changed, 194 insertions(+), 77 deletions(-) create mode 100644 config/Validation.php create mode 100644 modeles/Modèle/UserModel create mode 100644 modeles/Modèle/VisiteurModel delete mode 100644 views/styles/commonStyles.css diff --git a/config/Validation.php b/config/Validation.php new file mode 100644 index 0000000..5c0786e --- /dev/null +++ b/config/Validation.php @@ -0,0 +1,20 @@ + \ No newline at end of file diff --git a/controleurs/ControleurVisiteur.php b/controleurs/ControleurVisiteur.php index 59b22ed..a3bb829 100644 --- a/controleurs/ControleurVisiteur.php +++ b/controleurs/ControleurVisiteur.php @@ -17,20 +17,35 @@ class VisitorController { case "connection": $this->connection($arrayErrorViews); break; + case "inscription": + $this->inscription($arrayErrorViews); case "creerListe": $this->creerListe($arrayErrorViews); break; case "supprListe": $this->supprListe($arrayErrorViews); break; + case "creerTache": + $this->creerTache($arrayErrorViews); + break; + case "cocherTache": + $this->cocherTache($arrayErrorViews); + break; + case "supprTache": + $this->supprTache($arrayErrorViews); default : $arrayErrorViews[]="Erreur innatendue !!!"; require($rep.$vues['error']); } - }catch(PDOException $e){ + } catch(PDOException $e){ $dataView[]="Erreur inatendue"; require(__DIR__.'/../vues/erreur.php'); + } catch (Exception $e2) + { + $dVueEreur[] = "Erreur inattendue!!! "; + require ($rep.$vues['erreur']); } + exit(0); } public function reinit(){ @@ -40,7 +55,63 @@ class VisitorController { public function connection(array $vues_erreur){ global $rep,$vues; - require($rep.$vues['connection']); + + $usrname=$_POST['login']; + $pwd=$_POST['mdp']; + Validation::clear_string($pwd); + Validation::val_connexion($usrname,$pwd,$vues_erreur); + + $model = new UserModel(); + $worked=$model->connexion(); + /* + $dVue = array ( + 'username' => $usrname, + 'password' => $pwd, + 'worked' => $worked, + ); + */ + if($worked==false){ + require('erreur.php'); + } + } + + public function inscription(array $vues_erreur){ + global $rep,$vues; + + $usrname=$_POST['login']; + $pwd=$_POST['mdp']; + Validation::val_connexion($usrname,$pwd,$vues_erreur); + + $model = new UserModel(); + $model->inscription(); + } + + public function creerListe(array $vues_erreur){ + global $rep, $vues; + require($rep.$vues['creationListe']); + + $nom=$_POST['nom']; + + $model = new ListeModel(); + $model->creerListe($nom); + } + + public function supprListe(array $vues_erreur){ + global $rep, $vues; + require($rep.$vues['suppressionListe']); + + $model = new ListeModel(); + $model->supprListe(); + } + + public function creerTache(array $vues_erreur){ + global $rep, $vues; + require($rep.$vues['creerTache']); + + $intitule = $_POST['intitule']; + + $model = new ListeModel(); + $model->creerTache(); } } diff --git a/modeles/Gateways/ListeGateway.php b/modeles/Gateways/ListeGateway.php index d082a7a..c69b8f0 100644 --- a/modeles/Gateways/ListeGateway.php +++ b/modeles/Gateways/ListeGateway.php @@ -44,14 +44,14 @@ class ListeGateway { return $listes; } - public function creerTache(int $id, string $intitule, boolean $isCompleted){ + public function creerTache(string $intitule){ if(!empty($id) && !empty($intitutle)){ try{ $co = $this->co; - $query = "INSERT INTO Tache VALUES (:id, :intitule, :isCompleted)"; + $query = "INSERT INTO Tache VALUES (NULL, :intitule, 0)"; - $co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR), ':intitule' => array($nom, PDO::PARAM_STR), ':isCompleted' => array($taches, PDO::PARAM_STR))); + $co->executeQuery($query, array(':intitule' => array($nom, PDO::PARAM_STR))); } catch(PDOException $Exception){ echo 'erreur'; @@ -91,6 +91,39 @@ class ListeGateway { } } } + + public function creerListe(string $nom, string $idCreateur){ + if(!empty($id) && !empty($nom)){ + try{ + $co = $this->co; + + $query = "INSERT INTO Liste VALUES (NULL, :nom)"; + + $co->executeQuery($query, array(':nom' => array($nom, PDO::PARAM_STR))); + } + catch(PDOException $Exception){ + echo 'erreur'; + echo $Exception->getMessage(); + } + } + } + + public function delListe(int $id){ + if(!empty($id)){ + try{ + $co = $this->co; + + $query = "DELETE FROM Tache WHERE id=:id"; + + $co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR))); + } + catch(PDOException $Exception){ + echo 'erreur'; + echo $Exception->getMessage(); + } + } + } + } ?> \ No newline at end of file diff --git a/modeles/Gateways/UserGateway.php b/modeles/Gateways/UserGateway.php index 9dadc5a..ad6a852 100644 --- a/modeles/Gateways/UserGateway.php +++ b/modeles/Gateways/UserGateway.php @@ -10,14 +10,14 @@ class UserGateway { $this->co = $co; } - public function creerUtilisateur(int $id, string $nom, string $pwd){ + public function creerUtilisateur(string $nom, string $pwd){ if(!empty($id) && !empty($nom) && empty($password)){ try{ $co = $this->co; - $query = "INSERT INTO Utilisateur VALUES (:id, :nom, :pwd)"; + $query = "INSERT INTO Utilisateur VALUES (NULL, :nom, :pwd)"; - $co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR), ':nom' => array($nom, PDO::PARAM_STR), ':pwd' => array($pwd, PDO::PARAM_STR))); + $co->executeQuery($query, array(':nom' => array($nom, PDO::PARAM_STR), ':pwd' => array($pwd, PDO::PARAM_STR))); } catch(PDOException $Excception){ echo 'erreur'; @@ -115,38 +115,6 @@ class UserGateway { return $usr; } - public function creerListe(int $id, string $nom){ - if(!empty($id) && !empty($nom)){ - try{ - $co = $this->co; - - $query = "INSERT INTO Liste VALUES (:id, :nom, :taches)"; - - $co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR), ':nom' => array($nom, PDO::PARAM_STR), ':taches' => array($taches, PDO::PARAM_STR))); - } - catch(PDOException $Exception){ - echo 'erreur'; - echo $Exception->getMessage(); - } - } - } - - public function delListe(int $id){ - if(!empty($id)){ - try{ - $co = $this->co; - - $query = "DELETE FROM Tache WHERE id=:id"; - - $co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR))); - } - catch(PDOException $Exception){ - echo 'erreur'; - echo $Exception->getMessage(); - } - } - } - } ?> \ No newline at end of file diff --git a/modeles/Modèle/UserModel b/modeles/Modèle/UserModel new file mode 100644 index 0000000..02ffb61 --- /dev/null +++ b/modeles/Modèle/UserModel @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/modeles/Modèle/VisiteurModel b/modeles/Modèle/VisiteurModel new file mode 100644 index 0000000..7398b04 --- /dev/null +++ b/modeles/Modèle/VisiteurModel @@ -0,0 +1,48 @@ +gtwUsr = new UserGateway($co); + $this->gtwListe = new ListeGateway($co); + } + + public function get_gtwUsr(): UserGateway { + return $this->gtwUsr; + } + + public function get_gtwListe(): ListeGateway { + return $this->gtwListe; + } + + public function connexion($login, $mdp){ + $results = $this->get_gtwUsr()->getUtilisateurbyNameAndPassword($login, $mdp); + if ($results != NULL){ + $_SESSION['role'] = 'user'; + $_SESSION['login'] = $login; + return true; + } + return false; + } + + public function inscription($login, $mdp){ + $this->get_gtwUsr()->creerUtilisateur($login, $mdp); + } + + public function creerListe($nom) { + $this->get_gtwListe()->creerListe($nom, NULL); + } + + 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/modeles/Métier/Tache.php b/modeles/Métier/Tache.php index 1e22090..54721a3 100644 --- a/modeles/Métier/Tache.php +++ b/modeles/Métier/Tache.php @@ -4,13 +4,11 @@ Class Tache { private int $id; private string $intitule; private boolean $isCompleted; - private string $description; - function __construct(int $i, string $in, boolean $is, string $desc){ + function __construct(int $i, string $in, boolean $is){ $this->id = $i; $this->intitule = $in; $this->isCompleted = $is; - $this->description = $desc; } function get_id(): int { @@ -24,10 +22,6 @@ Class Tache { function get_isCompleted(): boolean { return $this->isCompleted; } - - function get_description(): string { - return $this->description; - } } ?> \ No newline at end of file diff --git a/views/styles/commonStyles.css b/views/styles/commonStyles.css deleted file mode 100644 index b6264e7..0000000 --- a/views/styles/commonStyles.css +++ /dev/null @@ -1,26 +0,0 @@ -header{ - display: flex; - flex-direction: row; - background-color: #0971C9; -} -body{ - background-color: #0D2350; - -} -h1,h2,h3,h4,p{ - font-family: sans-serif; - font-weight: bolder; - color: #6da8e2; -} -.button{ - width: 150%; - height: 75%; - background-color: #FFFEFD; - border-radius: 20%; - border-color: #0971C9; - color: #0D2350; - -} -.button:hover{ - background-color: grey; -} \ No newline at end of file diff --git a/vues/connection.php b/vues/connection.php index a25ae94..c939df4 100644 --- a/vues/connection.php +++ b/vues/connection.php @@ -10,9 +10,9 @@

Username

- +

Password

- +

diff --git a/vues/inscription.php b/vues/inscription.php index 4ffa4ee..4a54c48 100644 --- a/vues/inscription.php +++ b/vues/inscription.php @@ -12,9 +12,9 @@

Please enter all the informations :

Username

- +

Password

- +

Email

Date Of Birth