From a2acad71ca06000406806e12e02ab6637fbdcf75 Mon Sep 17 00:00:00 2001 From: Lucie Bedouret Date: Tue, 6 Dec 2022 15:35:44 +0100 Subject: [PATCH] =?UTF-8?q?ADD:=20ajout=20de=20m=C3=A9thodes=20dans=20le?= =?UTF-8?q?=20user=20controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controleurs/ControleurUtilisateur.php | 51 ++++++++++++++++++++++----- controleurs/ControleurVisiteur.php | 2 +- controleurs/FrontControleur.php | 4 +-- modeles/Gateways/ListeGateway.php | 34 ++++++++++++++++++ modeles/Gateways/UserGateway.php | 32 ----------------- modeles/Modele/UserModel.php | 28 +++++++++++++++ modeles/Modele/VisitorModel.php | 5 +-- modeles/Métier/Liste.php | 4 +-- modeles/Métier/Tache.php | 5 +++ views/connection.html | 27 -------------- views/error.html | 8 ----- views/signUp.html | 27 -------------- views/styles/commonStyles.css | 26 -------------- 13 files changed, 115 insertions(+), 138 deletions(-) create mode 100644 modeles/Modele/UserModel.php delete mode 100644 views/connection.html delete mode 100644 views/error.html delete mode 100644 views/signUp.html delete mode 100644 views/styles/commonStyles.css diff --git a/controleurs/ControleurUtilisateur.php b/controleurs/ControleurUtilisateur.php index ce551ce..50dd5d7 100644 --- a/controleurs/ControleurUtilisateur.php +++ b/controleurs/ControleurUtilisateur.php @@ -11,29 +11,62 @@ class UserController{ try{ $action = $_REQUEST['action']??null; switch($action){ - case NULL: - $this->reinit(); - break; case "deconnection": $this->deconnection($arrayErrorViews); break; - case "creerListePrivee": + case "creerListePv": $this->creerListe($arrayErrorViews); break; - case "supprListe": - $this->supprListe($arrayErrorViews); + case "desinscription": + $this->desinctription($arrayErrorViews); + break; + case "changerInfos": + $this->changerInfos($arrayErrorViews); break; - case "cocherTache": default : $arrayErrorViews[]="Erreur innatendue !!!"; require($rep.$vues['error']); } - */ }catch(PDOException $e){ $dataView[]="Erreur inatendue"; - require(__DIR__.'/../vues/erreur.php'); + require($rep.$vues['erreur']); } } + + public function deconnection($arrayErrorViews){ + // appeler la méthode deco du modèle + UserModel::deconnection(); + } + + public function creerListePv($arrayErrorViews){ + global $rep, $vues; + //recupérer les valeurs du formulaire + $nomListe=$_POST['ListName']; + $privee=$_POST['isPrivate']; + + // valider les champs + Validation::val_creation_Liste_PV($nomListe, $arrayErrorViews); + // vider les champs + //Validation::clear_string($_POST['ListName']); + // appelle à la methode du modèle + if($privee == true){ + UserModel::creerListePv($nomListe,$_SESSION['login']); + }else{ + VisitorModel::creerListe($nomListe); + } + } + + public function desinscription($arrayErrorViews){ + global $rep, $vues; + // recup valeurs des champs + $password=$_POST['password']; + // valider les champs + Validation::val_desinscription($password); + // vider les champs + //Validation::clear_string($_POST['password']); + // appel à la classe userModel + UserModel::desinscription($_SESSION['login']); + } } ?> \ No newline at end of file diff --git a/controleurs/ControleurVisiteur.php b/controleurs/ControleurVisiteur.php index 4008f25..db1e315 100644 --- a/controleurs/ControleurVisiteur.php +++ b/controleurs/ControleurVisiteur.php @@ -29,7 +29,7 @@ class VisitorController { } }catch(PDOException $e){ $dataView[]="Erreur inatendue"; - require(__DIR__.'/../vues/erreur.php'); + require($rep.$vues['erreur']); } } diff --git a/controleurs/FrontControleur.php b/controleurs/FrontControleur.php index ea1fadb..2efdf89 100644 --- a/controleurs/FrontControleur.php +++ b/controleurs/FrontControleur.php @@ -3,8 +3,8 @@ class FrontControleur{ public function __construct(){ - $liste_actions_utilisateur = array('deconnecter','crerListePrivee','supprListeprivee'); - $liste_actions_visiteur = array('ajoutListe','suprrListe','connecter'); + $liste_actions_utilisateur = array('deconnection','crerListePv','desinscription','changerInfos'); + $liste_actions_visiteur = array('creerListe','suprrListe','connection','inscription','creerTache','cocherTache','supprTache'); global $rep,$vues; require($rep.$vues['acceuil']); try{ diff --git a/modeles/Gateways/ListeGateway.php b/modeles/Gateways/ListeGateway.php index d082a7a..42827c1 100644 --- a/modeles/Gateways/ListeGateway.php +++ b/modeles/Gateways/ListeGateway.php @@ -91,6 +91,40 @@ class ListeGateway { } } } + + public function creerListe(string $nom, int $idCreator){ + try{ + $co = $this->co; + + $insertQuery = "INSERT INTO Liste VALUES (NULL, :nom, :idCreator)"; + + + $co->executeQuery($query, array('id' => array($id, PDO::PARAM_INT), + 'nom' => array($nom, PDO::PARAM_STR), + 'idCreator' => array($idCreator, PDO::PARAM_INT))); + } + 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..97b723d 100644 --- a/modeles/Gateways/UserGateway.php +++ b/modeles/Gateways/UserGateway.php @@ -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/Modele/UserModel.php b/modeles/Modele/UserModel.php new file mode 100644 index 0000000..08841dc --- /dev/null +++ b/modeles/Modele/UserModel.php @@ -0,0 +1,28 @@ +usergw = new UserGateway($co); + $this->listgw = new ListeGateway($co); + } + + public function deconnection(){ + session_unset(); + session_destroy(); + $_SESSION = array(); + } + + public function creerListePv($nom,$idCeator){ + $this->listgw->creerListe($nom,$idCreator); + } + + public function desinscription($login){ + $this->usergw->delUtilisateur($login); + } +} + +?> \ No newline at end of file diff --git a/modeles/Modele/VisitorModel.php b/modeles/Modele/VisitorModel.php index c814295..51e66a7 100644 --- a/modeles/Modele/VisitorModel.php +++ b/modeles/Modele/VisitorModel.php @@ -7,10 +7,7 @@ class VisitorModel{ $co = new Connection(); $this->gw = new ListeGateway($co); } - - public function creerListe(){ - - } + } ?> \ No newline at end of file diff --git a/modeles/Métier/Liste.php b/modeles/Métier/Liste.php index 10f104f..f4103f5 100644 --- a/modeles/Métier/Liste.php +++ b/modeles/Métier/Liste.php @@ -3,7 +3,7 @@ class Liste { private int $id; private string $nom; - private $taches; + private int $idCreator; function __construct(int $i, string $n, $t){ $this->id=$i; @@ -19,7 +19,7 @@ class Liste { return $this->nom; } - function get_taches(): array { + function get_idCreator(): array { return $this->taches; } } diff --git a/modeles/Métier/Tache.php b/modeles/Métier/Tache.php index 1e22090..133eace 100644 --- a/modeles/Métier/Tache.php +++ b/modeles/Métier/Tache.php @@ -5,6 +5,7 @@ Class Tache { private string $intitule; private boolean $isCompleted; private string $description; + private int $idListe; function __construct(int $i, string $in, boolean $is, string $desc){ $this->id = $i; @@ -28,6 +29,10 @@ Class Tache { function get_description(): string { return $this->description; } + + function get_idListe(): string { + return $this->idListe; + } } ?> \ No newline at end of file diff --git a/views/connection.html b/views/connection.html deleted file mode 100644 index d236ba0..0000000 --- a/views/connection.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - connection - - - -
-

You are back ?!

-
-
-

Username

- -

Password

- -
-
- -
-
-

You are new here?

- - - -
- - \ No newline at end of file diff --git a/views/error.html b/views/error.html deleted file mode 100644 index f72c671..0000000 --- a/views/error.html +++ /dev/null @@ -1,8 +0,0 @@ - - -
-

Error!

-

There was an error in the fields you filled...

-

Please enter correct values

-
- \ No newline at end of file diff --git a/views/signUp.html b/views/signUp.html deleted file mode 100644 index 4fcd0cb..0000000 --- a/views/signUp.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - connection - - - -
-

Join the good side of the force

- -
-
-

Please enter all the informations :

-

Username

- -

Password

- -

Email

- -

Date Of Birth

- -
-
- -
- - \ 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