From dadfbb7164f384fb48e1364c9dee040c9c59641a Mon Sep 17 00:00:00 2001 From: "jade.van_brabandt" Date: Wed, 25 Oct 2023 19:04:45 +0200 Subject: [PATCH] Build : Squelette du code :beers: --- Website/controllers/ControllerAdmin.php | 71 +++++++++++++++++++++++ Website/controllers/FrontController.php | 42 ++++++++++++++ Website/gateways/GatewayAdmin.php | 36 ++++++++++++ Website/models/Admin.php | 18 ++++++ Website/update/Appel.php | 13 +++++ Website/usages/Autoload.php | 46 +++++++++++++++ Website/usages/Config.php | 15 +++++ Website/usages/ConnectionBaseDeDonnee.php | 32 ++++++++++ 8 files changed, 273 insertions(+) create mode 100755 Website/controllers/ControllerAdmin.php create mode 100755 Website/controllers/FrontController.php create mode 100755 Website/gateways/GatewayAdmin.php create mode 100755 Website/models/Admin.php create mode 100755 Website/update/Appel.php create mode 100755 Website/usages/Autoload.php create mode 100755 Website/usages/Config.php create mode 100755 Website/usages/ConnectionBaseDeDonnee.php diff --git a/Website/controllers/ControllerAdmin.php b/Website/controllers/ControllerAdmin.php new file mode 100755 index 0000000..ee27cab --- /dev/null +++ b/Website/controllers/ControllerAdmin.php @@ -0,0 +1,71 @@ +validationConnexion(); + break; + case "quitterAdministrator": + $Administrator->deconnexion(); + header("location: index.php"); + break; + case "AjouterQuestion": + case "SupprimerQuestion": + case "ModifierQuestion": + case "AjouterReponse": + case "SupprimerReponse": + case "ModifierReponse": + case "AjouterAdmin": + case "SupprimerAdmin": + default: + break; + } + } catch (PDOException $e) { + // $dataVueEreur[] = "Erreur inattendue!!! "; + // require(__DIR__.'/../vues/erreur.php'); + } catch (Exception $e2) { + // $dataVueEreur[] = "Erreur inattendue!!! "; + // require ($rep.$vues['erreur']); + } + } + + function validationConnexion() + { + global $vues; + $validation = new Validation(); + $error = []; + $validation->val_form($_POST['name'], $_POST['password'], $error); + foreach ($error as $key) { + print($key); + } + + if (empty($error)) { + $validation = $Administrator->connection($_POST['name'], $_POST['password']); + if (!empty($validation)) { + header("location: index.php?action=goToAdministratoristration"); + } else { + header("location: index.php?action=goToAdministratorConnexion"); + } + } else { + header("location: index.php?action=goToAdministratorConnexion"); + } + } +} diff --git a/Website/controllers/FrontController.php b/Website/controllers/FrontController.php new file mode 100755 index 0000000..8822548 --- /dev/null +++ b/Website/controllers/FrontController.php @@ -0,0 +1,42 @@ +isAdministrator(); + $action = ""; + if (isset($_REQUEST['action'])) { + $action = $_REQUEST['action']; + } + if (in_array($action, $listeAction_Administrator)) { + if ($Administrator == NULL) { + new ControllerAdministrator(); + } else { + header("Location:" . $vues["AdministratorConnexion"]); + } + } else { + $gatewayNews = new GatewayNews(new Connection($dsn, $user, $pass)); + $page = 1; + if (isset($_GET['page'])) { + $page = $_GET['page']; + } + $gate = new GatewayConfigAdministrator(new Connection($dsn, $user, $pass)); + $nbArticlePages = $gate->getConfigAdministrator(1); + $listeNews = $gatewayNews->getNews($page, $nbArticlePages); + $pageAvant = $page - 1; + $pageApres = $page + 1; + + + $pageMAX = $gatewayNews->getNbNews() / $nbArticlePages + 1; + require($vues['listeNews']); + } + } catch (Exception $e) { + header("Location:" . $vues["erreur"]); + } + } +} diff --git a/Website/gateways/GatewayAdmin.php b/Website/gateways/GatewayAdmin.php new file mode 100755 index 0000000..0e8895f --- /dev/null +++ b/Website/gateways/GatewayAdmin.php @@ -0,0 +1,36 @@ +con = $con; + } + + public function addAdministrator($Administrator) + { + $query = "insert into Administratoristrator(id,username,password) values (:id,:username,:password);"; + $this->con->executeQuery( + $query, + array( + ':id' => array($Administrator->getId(), PDO::PARAM_INT), + ':username' => array($Administrator->getUsername(), PDO::PARAM_STR), + ':password' => array(password_hash($Administrator->getPassword(), PASSWORD_DEFAULT), PDO::PARAM_STR) + ) + ); + } + + + public function getCredential($login) + { + $query = "SELECT password FROM Administrator WHERE username = :login;"; + $this->con->executeQuery($query, array(':login' => array($login, PDO::PARAM_STR))); + $results = $this->con->getResults(); + if ($results == NULL) { + return false; + } + return $results[0]['password']; + } +} diff --git a/Website/models/Admin.php b/Website/models/Admin.php new file mode 100755 index 0000000..5abe7f9 --- /dev/null +++ b/Website/models/Admin.php @@ -0,0 +1,18 @@ +id = $id; + $this->username = $username; + } + + public function getUsername() + { + return $this->username; + } +} diff --git a/Website/update/Appel.php b/Website/update/Appel.php new file mode 100755 index 0000000..37b7bd9 --- /dev/null +++ b/Website/update/Appel.php @@ -0,0 +1,13 @@ + + diff --git a/Website/usages/Autoload.php b/Website/usages/Autoload.php new file mode 100755 index 0000000..b085456 --- /dev/null +++ b/Website/usages/Autoload.php @@ -0,0 +1,46 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } + + +/** * @param string $query + * @param array $parameters * + * @return bool Returns `true` on success, `false` otherwise +*/ + + public function executeQuery(string $query, array $parameters = []) : bool{ + $this->stmt = parent::prepare($query); + foreach ($parameters as $name => $value) { + $this->stmt->bindValue($name, $value[0], $value[1]); + } + + return $this->stmt->execute(); + } + + public function getResults() : array { + return $this->stmt->fetchall(); + + } +} + +?>