From e965bb63c730f738c14b56fdf81e153f3ae33fc1 Mon Sep 17 00:00:00 2001 From: samuel Date: Mon, 13 Nov 2023 15:25:34 +0100 Subject: [PATCH] insert changed for validator --- sql/setup-tables.sql | 2 +- src/Controller/AuthController.php | 2 +- src/Gateway/AuthGateway.php | 15 ++++++--------- src/Model/AuthModel.php | 6 ++++-- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/sql/setup-tables.sql b/sql/setup-tables.sql index 4f6e0d4..8a7debc 100644 --- a/sql/setup-tables.sql +++ b/sql/setup-tables.sql @@ -4,7 +4,7 @@ DROP TABLE IF EXISTS FormEntries; DROP TABLE IF EXISTS AccountUser; CREATE TABLE FormEntries(name varchar, description varchar); -CREATE TABLE AccountUser(name varchar, profilPicture varchar, age int); +CREATE TABLE AccountUser(username varchar, password varchar, email varchar); diff --git a/src/Controller/AuthController.php b/src/Controller/AuthController.php index b6285b2..27b5847 100644 --- a/src/Controller/AuthController.php +++ b/src/Controller/AuthController.php @@ -26,7 +26,7 @@ class AuthController { public function confirmRegister(array $request) { if (isset($request['username']) && isset($request['password']) && isset($request['confirmpassword']) && isset($request['email'])) { - $errors = $this->model->validationRegister($request["password"], $request['confirmpassword']); + $errors = $this->model->validationRegister($request['username'],$request["password"], $request['confirmpassword'],$request['email']); if (empty($errors)) { echo $this->twig->render("display_register_confirm.html.twig", [$request]); diff --git a/src/Gateway/AuthGateway.php b/src/Gateway/AuthGateway.php index 99ad300..1ae3fa3 100644 --- a/src/Gateway/AuthGateway.php +++ b/src/Gateway/AuthGateway.php @@ -3,24 +3,21 @@ namespace App\Gateway; use App\Connexion; +use \PDO; -class AuthGateway -{ +class AuthGateway { private Connexion $con; /** * @param Connexion $con */ - public function __construct(Connexion $con) - { + public function __construct(Connexion $con) { $this->con = $con; } - public function insertAccount (string $username, string $password, string $email){ - - - $this->con->exec("INSERT INTO AccountUser VALUES ($username,$password,$email)"); + public function insertAccount(string $username, string $password, string $email) { + $this->con->exec("INSERT INTO AccountUser VALUES (:username,:password,:email)", [':username' => [$username, PDO::PARAM_STR],':password'=> [$password, PDO::PARAM_STR],':email'=>[$email, PDO::PARAM_STR]]); } -} \ No newline at end of file +} \ No newline at end of file diff --git a/src/Model/AuthModel.php b/src/Model/AuthModel.php index 8ced973..c591e6c 100644 --- a/src/Model/AuthModel.php +++ b/src/Model/AuthModel.php @@ -18,13 +18,15 @@ class AuthModel { } - public function validationRegister(string $password, string $confirmPassword): array { + public function validationRegister(string $username, string $password, string $confirmPassword,string $email): array { $errors = []; if ($password != $confirmPassword) { $errors[] = self::PASSWORD_CONFIRM_NOT_EQUALS; } - // si pas d'erreurs alors on appelle la gateway + else{ + $this->gateway->insertAccount($username,$password,$email); + }// si pas d'erreurs alors on appelle la gateway return $errors; }