From 0ffbfc39b243095e414f46d088cec847002779af Mon Sep 17 00:00:00 2001 From: "maxime.point2" Date: Wed, 15 Nov 2023 09:03:12 +0100 Subject: [PATCH] :poop: ajout de admin et modif ArticleModel --- fluxRSS/DAL/AdminGateway.php | 27 +++++++++++++++++++++ fluxRSS/DAL/ArticleGateway.php | 39 +++++++++++++++++++++---------- fluxRSS/DAL/FluxGateway.php | 36 ++++++++++++++++++++-------- fluxRSS/composer.json | 3 ++- fluxRSS/controleur/Controleur.php | 2 +- fluxRSS/index.php | 3 +++ fluxRSS/metier/Admin.php | 0 fluxRSS/model/AdminModel.php | 25 ++++++++++++++++++++ fluxRSS/model/ArticleModel.php | 11 ++++++--- fluxRSS/model/FluxModel.php | 14 +++++------ fluxRSS/model/Parser.php | 0 11 files changed, 126 insertions(+), 34 deletions(-) create mode 100755 fluxRSS/DAL/AdminGateway.php mode change 100644 => 100755 fluxRSS/metier/Admin.php create mode 100755 fluxRSS/model/AdminModel.php mode change 100644 => 100755 fluxRSS/model/Parser.php diff --git a/fluxRSS/DAL/AdminGateway.php b/fluxRSS/DAL/AdminGateway.php new file mode 100755 index 0000000..f2b06c0 --- /dev/null +++ b/fluxRSS/DAL/AdminGateway.php @@ -0,0 +1,27 @@ +con = $con; + } + + public function login(string $login):array + { + try{ + $query = 'SELECT mdp,mail FROM Admin WHERE login = :login;'; + $this->con->executeQuery($query, array(':flux' => array($login, PDO::PARAM_STR))); + return $this->con->getResults(); + }catch (\PDOException $e){ + throw new \Exception("PDO error"); + } + } +} \ No newline at end of file diff --git a/fluxRSS/DAL/ArticleGateway.php b/fluxRSS/DAL/ArticleGateway.php index a36f565..7818920 100755 --- a/fluxRSS/DAL/ArticleGateway.php +++ b/fluxRSS/DAL/ArticleGateway.php @@ -1,6 +1,7 @@ con = $con; } + /** + * @throws Exception + */ public function getAllArticles():array { - $query = 'SELECT * FROM Article;'; - $this->con->executeQuery($query, array()); - return $this->con->getResults(); + try { + $query = 'SELECT * FROM Article;'; + $this->con->executeQuery($query, array()); + return $this->con->getResults(); + }catch (\PDOException $e){ + throw new Exception("PDO error"); + } } + /** + * @throws Exception + */ public function addArticle(Article $article){ - $query = 'INSERT INTO Article VALUES (:id,:title,to_date(:date,"Dy, DD Mon YYYY"),:description,:guid,:link,:mediaContent,:provenance);'; - $this->con->executeQuery($query, array( ':id' => array($article->getId(), PDO::PARAM_STR), - ':title' => array($article->getTitle(), PDO::PARAM_STR), - ':date' => array($article->getDate(),PDO::PARAM_STR), - ':description' => array($article->getDescription(),PDO::PARAM_STR), - ':guid' => array($article->getGuid(),PDO::PARAM_STR), - ':link' => array($article->getLink(),PDO::PARAM_STR), - ':mediaContent' => array($article->getMediaContent(),PDO::PARAM_STR), - ':provenance' => array($article->getProvenance(),PDO::PARAM_INT))); + try { + $query = 'INSERT INTO Article VALUES (:id,:title,to_date(:date,"Dy, DD Mon YYYY"),:description,:guid,:link,:mediaContent,:provenance);'; + $this->con->executeQuery($query, array(':id' => array($article->getId(), PDO::PARAM_STR), + ':title' => array($article->getTitle(), PDO::PARAM_STR), + ':date' => array($article->getDate(), PDO::PARAM_STR), + ':description' => array($article->getDescription(), PDO::PARAM_STR), + ':guid' => array($article->getGuid(), PDO::PARAM_STR), + ':link' => array($article->getLink(), PDO::PARAM_STR), + ':mediaContent' => array($article->getMediaContent(), PDO::PARAM_STR), + ':provenance' => array($article->getProvenance(), PDO::PARAM_INT))); + }catch (\PDOException $e){ + throw new Exception("PDO error"); + } } } \ No newline at end of file diff --git a/fluxRSS/DAL/FluxGateway.php b/fluxRSS/DAL/FluxGateway.php index 57ca526..43bbe9f 100755 --- a/fluxRSS/DAL/FluxGateway.php +++ b/fluxRSS/DAL/FluxGateway.php @@ -14,19 +14,31 @@ class FluxGateway } public function addFlux($flux){ - $query = 'INSERT INTO Flux VALUES (:flux);'; - $this->con->executeQuery($query, array(':flux' => array($flux->getFlux(), PDO::PARAM_STR))); + try{ + $query = 'INSERT INTO Flux VALUES (:flux);'; + $this->con->executeQuery($query, array(':flux' => array($flux->getFlux(), PDO::PARAM_STR))); + }catch (\PDOException $e){ + throw new \Exception("PDO error"); + } } public function removeFlux($flux){ - $query = 'DELETE FROM Flux WHERE flux = :flux;'; - $this->con->executeQuery($query, array(':flux' => array($flux->getFlux(), PDO::PARAM_STR))); + try{ + $query = 'DELETE FROM Flux WHERE flux = :flux;'; + $this->con->executeQuery($query, array(':flux' => array($flux->getFlux(), PDO::PARAM_STR))); + }catch (\PDOException $e){ + throw new \Exception("PDO error"); + } } public function findAllFlux(){ - $query = 'SELECT * FROM Flux;'; - $this->con->executeQuery($query); - return $this->con->getResults(); + try{ + $query = 'SELECT * FROM Flux;'; + $this->con->executeQuery($query); + return $this->con->getResults(); + }catch (\PDOException $e){ + throw new \Exception("PDO error"); + } } public function findFlux(Flux $flux){ @@ -34,8 +46,12 @@ class FluxGateway } public function findFluxBySrc(string $flux){ - $query = 'SELECT * FROM Flux WHERE flux = :flux;'; - $this->con->executeQuery($query, array(':flux' => array($flux, PDO::PARAM_STR))); - return $this->con->getResults(); + try{ + $query = 'SELECT * FROM Flux WHERE flux = :flux;'; + $this->con->executeQuery($query, array(':flux' => array($flux, PDO::PARAM_STR))); + return $this->con->getResults(); + }catch (\PDOException $e){ + throw new \Exception("PDO error"); + } } } \ No newline at end of file diff --git a/fluxRSS/composer.json b/fluxRSS/composer.json index bb8dfdb..2ef7dc7 100755 --- a/fluxRSS/composer.json +++ b/fluxRSS/composer.json @@ -9,7 +9,8 @@ "controleur\\": "controleur/", "config\\": "config/", "model\\": "model/", - "DAL\\": "DAL/" + "DAL\\": "DAL/", + "metier\\": "metier/" } } } diff --git a/fluxRSS/controleur/Controleur.php b/fluxRSS/controleur/Controleur.php index ca4318e..5fbf48a 100755 --- a/fluxRSS/controleur/Controleur.php +++ b/fluxRSS/controleur/Controleur.php @@ -9,7 +9,6 @@ class Controleur { global $twig; // nécessaire pour utiliser variables globales session_start(); - $tabArticle[] = ArticleModel::getArticles(); //debut //on initialise un tableau d'erreur @@ -30,6 +29,7 @@ class Controleur //mauvaise action default: + $tabArticle[] = ArticleModel::getArticles(); $dVueEreur[] = "Erreur d'appel php"; $dataview = ['Article'=> $tabArticle]; echo $twig->render('listArticle.html', ['tabArticle' => $dataview, 'dVueErreur'=>$dVueEreur]); diff --git a/fluxRSS/index.php b/fluxRSS/index.php index 0ceef5c..0e8dfd4 100755 --- a/fluxRSS/index.php +++ b/fluxRSS/index.php @@ -1,4 +1,5 @@ login($username); + + foreach ($lmdp as $motDePasse){ + if (password_verify($mdp,$motDePasse['mdp'])){ + $_SESSION['role'] = 'admin'; + $_SESSION['pseudo'] = $username; + return new Admin($username,$motDePasse['mail']); + } + } + return null; + } +} \ No newline at end of file diff --git a/fluxRSS/model/ArticleModel.php b/fluxRSS/model/ArticleModel.php index 3c7758b..6e23116 100755 --- a/fluxRSS/model/ArticleModel.php +++ b/fluxRSS/model/ArticleModel.php @@ -2,18 +2,23 @@ namespace model; -use DAL\{ArticleGateway,Connection}; +use DAL\{AdminGateway, ArticleGateway, Connection}; use metier; +require ('../DAL/ArticleGateway.php'); +require ('../DAL/Connection.php'); class ArticleModel { public static function getArticles() : array { - $gwArticle = new ArticleGateway(new Connection('mysql:host = localhost; dbname = dbrorossetto', 'rorossetto', 'tpphp')); + $gwArticle = new ArticleGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); + $tabArticle = array(); $res = $gwArticle->getAllArticles(); foreach($res as $row){ $tabArticle[] = new metier\Article($row['id'], $row['title'],$row['datePub'],$row['description'],$row['guid'],$row['link'],$row['mediaContent'],$row['provenance'] ); } return $tabArticle; } -} \ No newline at end of file +} + +var_dump(ArticleModel::getArticles()); \ No newline at end of file diff --git a/fluxRSS/model/FluxModel.php b/fluxRSS/model/FluxModel.php index 5f9f882..5116de9 100755 --- a/fluxRSS/model/FluxModel.php +++ b/fluxRSS/model/FluxModel.php @@ -10,7 +10,7 @@ require_once "config/config.php"; class FluxModel { public function FindAllFlux(){ - $gateway = new FluxGateway(new Connection( $base, $login, $mdp)); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); $data = array(); $result = $gateway->findAllFlux(); @@ -21,7 +21,7 @@ class FluxModel } public function addFlux(Flux $flux){ - $gateway = new FluxGateway(new Connection( $base, $login, $mdp)); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); $data = $this->findFlux($flux); if ($data == array()) { $gateway->addFlux($flux); @@ -29,26 +29,26 @@ class FluxModel } public function addFluxBySrc(string $flux): Flux { - $gateway = new FluxGateway(new Connection( $base, $login, $mdp)); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); $newFlux = new Flux($flux); $gateway->addFlux($newFlux); return $newFlux; } public function removeFlux(Flux $flux){ - $gateway = new FluxGateway(new Connection( $base, $login, $mdp)); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); $gateway->removeFlux($flux); } public function removeFluxBySrc(string $flux): Flux { - $gateway = new FluxGateway(new Connection( $base, $login, $mdp)); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); $newFlux = new Flux($flux); $gateway->removeFlux($newFlux); return $newFlux; } public function findFlux(Flux $flux){ - $gateway = new FluxGateway(new Connection( $base, $login, $mdp)); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); $data = array(); $result = $gateway->findFlux($flux); @@ -59,7 +59,7 @@ class FluxModel } public function findFluxBySrc(string $flux){ - $gateway = new FluxGateway(new Connection( $base, $login, $mdp)); + $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); $data = array(); $result = $gateway->findFluxBySrc($flux); diff --git a/fluxRSS/model/Parser.php b/fluxRSS/model/Parser.php old mode 100644 new mode 100755