diff --git a/WEB/Config/Config.php b/WEB/Config/Config.php index e0c6b63b..78c5f776 100644 --- a/WEB/Config/Config.php +++ b/WEB/Config/Config.php @@ -14,7 +14,7 @@ $rep = __DIR__ . '/../'; // $password = 'p'; // SQULITE3 -$dsn = './Model/scripted.db'; +$dsn = './Model/scripted.db'; //Sel de hashage $sel = "JeSuisUnSeldeHashageEtJeSuisUniqueEtTresSecuriseEtJeSuisTresLong"; diff --git a/WEB/Config/Connection.php b/WEB/Config/Connection.php index 0ecf2b5e..987a2594 100644 --- a/WEB/Config/Connection.php +++ b/WEB/Config/Connection.php @@ -21,13 +21,14 @@ class Connection extends SQLite3 { private $stmt; private $result; - function __construct($dsn) - { - $this->open($dsn); - } + function __construct($dsn) + { + $this->open($dsn); + $this->enableExceptions(true); + } public function executeQuery(string $query, array $parameters = []) :bool { - $this->stmt = $this->prepare($query); + $this->stmt = parent::prepare($query); foreach ($parameters as $name => $value) { $this->stmt->bindValue($name, $value[0], $value[1]); } @@ -38,4 +39,11 @@ class Connection extends SQLite3 public function getResults(): array { return $this->result->fetchArray(); } -} \ No newline at end of file +} + +// class Connection extends SQLite3{ +// function __construct() +// { +// $this->open("./Model/scripted.db"); +// } +// } \ No newline at end of file diff --git a/WEB/Controller/FrontController.php b/WEB/Controller/FrontController.php index 63c0cc00..8870beaf 100644 --- a/WEB/Controller/FrontController.php +++ b/WEB/Controller/FrontController.php @@ -3,7 +3,7 @@ class FrontController { function __construct() { - global $rep, $vues; + global $rep, $vues, $error; session_start(); // $role=$_SESSION['role']; // $action=$_REQUEST['action']; diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 6b213a95..a1fc969e 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -6,9 +6,9 @@ class UserController function __construct() { try{ + echo "UserController"; global $dsn, $rep, $vues, $error; - echo "userController"; - $this->con=new Connection ($dsn); + $this->con=new Connection($dsn); echo "USconection"; $action=$_REQUEST['action']; switch($action) { @@ -71,7 +71,8 @@ class UserController throw (new Exception("Email déjà utilisé")); } $password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT); - $Utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password, false); + $estAdmin = $gateway->getEstAdminByEmail($_REQUEST['email']); + $Utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password, $estAdmin); $gateway->insert($Utilisateur); $_SESSION['connected'] = 'true'; $_SESSION['role'] = 'utilisateur'; diff --git a/WEB/Controller/UtilisateurGateway.php b/WEB/Controller/UtilisateurGateway.php index ac2d7127..7e87d809 100644 --- a/WEB/Controller/UtilisateurGateway.php +++ b/WEB/Controller/UtilisateurGateway.php @@ -22,16 +22,16 @@ class UtilisateurGateway public function insert(Utilisateur $utilisateur) : void{ $query = "INSERT INTO Utilisateur VALUE (:email,:pseudo,:mdp,:estAdmin)"; $this->con->executeQuery($query, array( - ':email' => array($utilisateur->getEmail(),SQLITE3_TEXT), - ':pseudo' => array($utilisateur->getPseudo(),SQLITE3_TEXT), - ':mdp' => array($utilisateur->getMdp(),SQLITE3_TEXT), - ':estAdmin' => array($utilisateur->getEstAdmin(),SQLITE3_INTEGER))); + ':email' => array($utilisateur->getEmail(),PDO::PARAM_STR), + ':pseudo' => array($utilisateur->getPseudo(),PDO::PARAM_STR), + ':mdp' => array($utilisateur->getMdp(),PDO::PARAM_STR), + ':estAdmin' => array($utilisateur->getEstAdmin(),PDO::PARAM_BOOL))); } public function delete(string $email) : void{ $query = "DELETE FROM utilisateur WHERE email=:email"; $this->con->executeQuery($query, array( - ':email' => array($email ,SQLITE3_TEXT) + ':email' => array($email ,PDO::PARAM_STR) )); } @@ -39,7 +39,7 @@ class UtilisateurGateway global $error; $query = "SELECT * FROM Utilisateur WHERE email=:email"; $this->con->executeQuery($query, array( - ':email' => array($email,SQLITE3_TEXT) + ':email' => array($email,PDO::PARAM_STR) )); $results=$this->con->getResults(); foreach ($results as $row) { @@ -58,7 +58,7 @@ class UtilisateurGateway global $error; $query = "SELECT mdp FROM Utilisateur WHERE email=:email"; $this->con->executeQuery($query, array( - ':email' => array($email,SQLITE3_TEXT) + ':email' => array($email,PDO::PARAM_STR) )); $results=$this->con->getResults(); foreach ($results as $row) { @@ -72,10 +72,9 @@ class UtilisateurGateway } public function getEstAdminByEmail(string $email) : bool{ - global $error; $query = "SELECT estAdmin FROM Utilisateur WHERE email=:email"; $this->con->executeQuery($query, array( - ':email' => array($email,SQLITE3_TEXT) + ':email' => array($email,PDO::PARAM_STR) )); $results=$this->con->getResults(); foreach ($results as $row) { diff --git a/WEB/Model/Utilisateur.php b/WEB/Model/Utilisateur.php index b77d042b..8cc430a0 100644 --- a/WEB/Model/Utilisateur.php +++ b/WEB/Model/Utilisateur.php @@ -13,20 +13,12 @@ class Utilisateur * @param string $mdp * @param bool $estAdmin */ -<<<<<<< HEAD public function __construct(string $email, string $pseudo, string $mdp, bool $estAdmin) -======= - public function __construct(string $email, string $pseudo, string $mdp ,bool $estAdmin) ->>>>>>> d82ece50 (Changement de joueur et admin) { $this->email = $email; $this->pseudo = $pseudo; $this->mdp = $mdp; -<<<<<<< HEAD $this->estAdmin = $estAdmin; -======= - $this->estAdmin=$estAdmin; ->>>>>>> d82ece50 (Changement de joueur et admin) } /** @@ -78,31 +70,17 @@ class Utilisateur } /** -<<<<<<< HEAD - * @return bool -======= * @param bool $estAdmin ->>>>>>> d82ece50 (Changement de joueur et admin) */ public function getEstAdmin(): bool { return $this->estAdmin; } -<<<<<<< HEAD /** * @param bool $estAdmin */ public function setEstAdmin(bool $estAdmin): void { $this->estAdmin = $estAdmin; -======= - - /** - * @param bool $estAdmin - */ - public function setEstAdmin(bool $estAdmin) - { - $this->estAdmin=$estAdmin; ->>>>>>> d82ece50 (Changement de joueur et admin) } } \ No newline at end of file diff --git a/WEB/index.php b/WEB/index.php index a9704cb1..6e187b71 100644 --- a/WEB/index.php +++ b/WEB/index.php @@ -18,9 +18,10 @@ Autoload::charger(); // } echo "test"; +$db = new Connection($dsn); +echo "test2"; $control = new FrontController(); - //session_regenerate_id(true); // session_unset(); // session_destroy();