From e71d839e33e1ec8344603581cb7863a0331806ef Mon Sep 17 00:00:00 2001 From: Alexis FERON Date: Wed, 15 Nov 2023 18:29:11 +0100 Subject: [PATCH] unification variables de la base --- php/src/config/config.php | 6 +----- php/src/modele/ImageModele.php | 2 +- php/src/modele/OffreModele.php | 6 +++--- php/src/modele/UtilisateurModele.php | 18 +++--------------- 4 files changed, 8 insertions(+), 24 deletions(-) diff --git a/php/src/config/config.php b/php/src/config/config.php index 40be1c1..ff7c8f1 100755 --- a/php/src/config/config.php +++ b/php/src/config/config.php @@ -6,13 +6,9 @@ $rep = __DIR__ . '/php/'; // liste des modules à inclure $dConfig['includes']= array('controleur/Validation.php'); -//BD -$base = 'mysql:host=localhost;dbname=dbAlica'; -$login = 'test'; -$mdp = 'test'; - static $OffersByPage = 5; +// Variables connexion à la base : à modifier en fonction de la base de chacun define('DB_HOST', 'mysql:host=localhost;dbname=dbAlica'); define('DB_USER', 'Dev'); define('DB_PASS', 'Dev'); diff --git a/php/src/modele/ImageModele.php b/php/src/modele/ImageModele.php index 9f40858..26743c0 100644 --- a/php/src/modele/ImageModele.php +++ b/php/src/modele/ImageModele.php @@ -10,7 +10,7 @@ class ImageModele private ImageGateway $gw; public function __construct() { - $this->gw = new ImageGateway(new Connection("mysql:host=localhost;dbname=dbAlica","test","test")); + $this->gw = new ImageGateway(new Connection(DB_HOST,DB_USER,DB_PASS)); } public function publierImage(string $file) : Image diff --git a/php/src/modele/OffreModele.php b/php/src/modele/OffreModele.php index 9b15426..d37c17a 100644 --- a/php/src/modele/OffreModele.php +++ b/php/src/modele/OffreModele.php @@ -18,7 +18,7 @@ class OffreModele public function __construct() { - $this->offreGw = new OffreGateway(new Connection("mysql:host=localhost;dbname=dbAlica", "test", "test")); + $this->offreGw = new OffreGateway(new Connection(DB_HOST,DB_USER,DB_PASS)); } public function publishOffer(string $img, string $logo) @@ -86,13 +86,13 @@ class OffreModele public function CreateOffersFromGw($res) : array { - $alGw = new AlumniGateway(new Connection("mysql:host=localhost;dbname=dbAlica", "test", "test")); + $alGw = new AlumniGateway(new Connection(DB_HOST,DB_USER,DB_PASS)); $offers=[]; foreach ($res as $row) { $resal = $alGw->ObtenirById($row['offreur']); - $profilGw = new ProfilGateway(new Connection("mysql:host=localhost;dbname=dbAlica", "Dev", "Dev")); + $profilGw = new ProfilGateway(new Connection(DB_HOST,DB_USER,DB_PASS)); $resProfl = $profilGw->getProfilById($row['offreur']); $alumni = new Alumni($resal[0]['mail'],$resal[0]['mdp'],$resal[0]['role'],$resProfl[0]['nom'],$resProfl[0]["prenom"]); diff --git a/php/src/modele/UtilisateurModele.php b/php/src/modele/UtilisateurModele.php index 375c61e..25e39a7 100755 --- a/php/src/modele/UtilisateurModele.php +++ b/php/src/modele/UtilisateurModele.php @@ -21,11 +21,7 @@ class UtilisateurModele public function connection(string $email, string $mdp) : ? \App\metier\Alumni { - $dsn = "mysql:host=localhost;dbname=dbAlica"; - $username = "Dev"; - $password = "Dev"; - - $con = new \App\gateway\Connection($dsn, $username, $password); + $con = new \App\gateway\Connection(DB_HOST,DB_USER,DB_PASS); $gate = new \App\gateway\AlumniGateway($con); // Récupérez l'utilisateur avec l'email donné en utilisant AlumniGateway $utilisateur = $gate->findByEmail($email); @@ -55,12 +51,8 @@ class UtilisateurModele public function inscription(string $prenom, string $nom,string $email, string $hashpassword):? \App\metier\Alumni { - $dsn = "mysql:host=localhost;dbname=dbAlica"; - $username = "test"; - $password = "test"; - $role = "Membre"; - $con = new \App\gateway\Connection($dsn, $username, $password); + $con = new \App\gateway\Connection(DB_HOST,DB_USER,DB_PASS); $gate = new \App\gateway\AlumniGateway($con); $profilGate = new \App\gateway\ProfilGateway($con); // Insérez le nouvel utilisateur dans la base de données en utilisant AlumniGateway @@ -88,11 +80,7 @@ class UtilisateurModele public function getUtilisateurByEmail(string $email) { - $dsn = "mysql:host=localhost;dbname=dbAlica"; - $username = "Dev"; - $password = "Dev"; - - $con = new \App\gateway\Connection($dsn, $username, $password); + $con = new \App\gateway\Connection(DB_HOST,DB_USER,DB_PASS); $gate = new \App\gateway\AlumniGateway($con); // Récupérez l'utilisateur avec l'email donné en utilisant AlumniGateway $utilisateur = $gate->findByEmail($email);