diff --git a/config/config.php b/config/config.php index 6088200..65bc07d 100644 --- a/config/config.php +++ b/config/config.php @@ -16,13 +16,12 @@ $mdp = ''; $vues['erreur'] = 'vue/erreur.php'; $vues['accueil'] = 'vue/accueil.php'; $vues['quote'] = 'vue/quote.php'; +$vues['profil'] = 'vue/profil.php'; $vues['login'] = 'vue/login.php'; $vues['signin'] = 'vue/signin.php'; $vues['quiz'] = 'vue/quiz.html'; $vues['search'] = 'vue/search.php'; $vues['favorite'] = 'vue/favorits.php'; -$vues['profil'] = 'vue/profil.php'; - //Style css diff --git a/index.php b/index.php index 04f4bbb..a490e89 100644 --- a/index.php +++ b/index.php @@ -1,10 +1,15 @@ listAction = ['visitor' => array('accueil','search','quote','login','signin'), + $this->listAction = ['visitor' => array('accueil','search','quote','login','signin','validlogin','validsignin'), 'user' => array('quiz','commentary','logout','addComment','favorite','profil'), 'admin' => array('null')]; @@ -43,8 +41,10 @@ Class FrontControler{ $router->map('GET|POST', '/profil', 'UserControler','profil'); $router->map('GET|POST', '/login', 'VisitorControler','login'); $router->map('GET|POST', '/signin', 'VisitorControler','signin'); + $router->map('GET|POST', '/validlogin', 'VisitorControler','validlogin'); + $router->map('GET|POST', '/validsignin', 'VisitorControler','validsignin'); + - $match = $router->match(); $action = NULL; @@ -92,9 +92,9 @@ Class FrontControler{ } private function verifDroit(string $action):bool { - if( in_array($action , $this->listAction['admin']) && $this->role == 'admin') return true; - elseif( in_array($action , $this->listAction['user']) && ($this->role == 'admin' || $this->role == 'user') ) return true; - elseif(in_array($action , $this->listAction['visitor']) && ($this->role == 'admin'|| $this->role == 'user'|| $this->role == 'visitor')) return true; + if( in_array($action , $this->listAction['admin']) && $_SESSION["role"] == 'admin') return true; + elseif( in_array($action , $this->listAction['user']) && ($_SESSION["role"] == 'admin' || $_SESSION["role"] == 'user') ) return true; + elseif(in_array($action , $this->listAction['visitor']) && ($_SESSION["role"] == 'admin'|| $_SESSION["role"] == 'user'|| $_SESSION["role"] == 'visitor')) return true; return false; } diff --git a/src/Controleur/UserControler.php b/src/Controleur/UserControler.php index e509422..3ab20f3 100644 --- a/src/Controleur/UserControler.php +++ b/src/Controleur/UserControler.php @@ -37,14 +37,14 @@ class UserControler { public function addComment(){ $id = $_POST['idQuote']; $this->cMod->createComment($_POST['content'],$_POST['idQuote'],$this->uMod->getIdByUsername($_SESSION['user'])); - header("Location: /~kemondejar/WF-Website/quote/$id"); + header("Location: /~kekentin/WF/WF-Website/quote/$id"); } public function favorite(array $args) { global $vues; - $userId = 1; + $userId = $this->uMod->getIdByUsername($_SESSION["user"]); $favorites = $this->quoteGateway->getFavorites($userId); diff --git a/src/Controleur/VisitorControler.php b/src/Controleur/VisitorControler.php index b34a23a..3cc128b 100644 --- a/src/Controleur/VisitorControler.php +++ b/src/Controleur/VisitorControler.php @@ -81,30 +81,21 @@ Class VisitorControler { require_once $vues['search']; } - /** * @throws SyntaxError * @throws RuntimeError * @throws LoaderError */ - public function getAction(string $action): void + public function login() { - switch ($action) { - case "login": - $this -> visitorLogIn(); - break; - case "signin": - $this -> visitorSignIn(); - break; - case "validsignin": - $this -> toSignIn(); - break; - case "validlogin": - $this -> toLogIn(); - break; - default: - break; - } + global $vues; + require_once $vues['login']; + + // global $twig; + + // echo $twig->render("login.html.twig"); + + //$this -> toLogIn(); } /** @@ -112,20 +103,19 @@ Class VisitorControler { * @throws RuntimeError * @throws LoaderError */ - public function login() + public function signin(): void { global $vues; - require_once $vues['login']; + require_once $vues['signin']; + } - // global $twig; - // echo $twig->render("login.html.twig"); - $this -> toLogIn(); - } - public function toLogIn() : void + + public function validlogin() : void { + global $vues; if ($_POST) { $pseudo = $_POST['pseudo'] ?? null; @@ -139,49 +129,34 @@ Class VisitorControler { { $_SESSION['user'] = $pseudo; $_SESSION['role'] = 'user'; - header("Location: /"); + header("Location: /~kekentin/WF/WF-Website/"); exit(); }else { global $twig; - $this -> errors = ["Identifiant ou mot de passe incorrect"]; - echo $twig -> render("login.html.twig", ['error' => $this -> errors[0]]); + $errors = "Identifiant ou mot de passe incorrect"; + require_once $vues['login']; exit(); } } else { global $twig; - $this -> errors = ["Identifiant ou mot de passe incorrect"]; - echo $twig -> render("login.html.twig", ['error' => $this -> errors[0]]); + $errors = "Identifiant ou mot de passe incorrect"; + require_once $vues['login']; exit(); } } } - - /** - * @throws SyntaxError - * @throws RuntimeError - * @throws LoaderError - */ - public function signin(): void - { - global $twig; - echo $twig->render("signin.html.twig"); - } - - /** * @throws RuntimeError * @throws SyntaxError * @throws LoaderError */ - public function toSignIn() : void + public function validsignin() : void { - global $twig; - - $this -> errors = [null, null, null]; + global $vues; if ($_POST) { $pseudo = $_POST['pseudo'] ?? null; @@ -190,9 +165,9 @@ Class VisitorControler { $cmdp = $_POST['cmdp'] ?? null; if ($mdp != $cmdp) { - $this->errors[2] = "Mots de passe incorrects"; - //$this->visitorSignIn(); - echo $twig->render("signin.html.twig", ['error' => $this->errors]); + $errors[2] = "Mots de passe incorrects"; + + require_once $vues['signin']; exit(); } $option = ['cost' => 12]; @@ -202,20 +177,27 @@ Class VisitorControler { $isEmailAlreadyUsed = $this -> mdl -> getEmail($email); if ($isUserAlreadyUsed and !$isEmailAlreadyUsed) { - $this->errors[0] = "Pseudo déjà utilisé"; - echo $twig->render("signin.html.twig", ['error' => $this->errors]); + $errors[0] = "Pseudo déjà utilisé"; + require_once $vues['signin']; exit(); } else if ($isEmailAlreadyUsed and !$isUserAlreadyUsed) { - $this->errors[1] = "Email déjà utilisé"; - echo $twig->render("signin.html.twig", ['error' => $this->errors]); + $errors[1] = "Email déjà utilisé"; + require_once $vues['signin']; + exit(); + } + else if ($isEmailAlreadyUsed and $isUserAlreadyUsed) { + $errors[0] = "Pseudo déjà utilisé"; + $errors[1] = "Email déjà utilisé"; + require_once $vues['signin']; exit(); } else echo $this->mdl->insertUser($pseudo, $email, $hmdp); - $_SESSION["pseudo"] = $pseudo; + $_SESSION["role"] = 'user'; + $_SESSION["user"] = $pseudo; - header("Location: /"); + header("Location: /~kekentin/WF/WF-Website/profil"); } } } \ No newline at end of file diff --git a/src/Entity/userEntity.php b/src/Entity/userEntity.php deleted file mode 100644 index ae58b54..0000000 --- a/src/Entity/userEntity.php +++ /dev/null @@ -1,158 +0,0 @@ -id; - } - - public function setId(int $id): void - { - $this->id = $id; - } - - public function getPseudo(): string - { - return $this->pseudo; - } - - public function setPseudo(string $pseudo): void - { - $this->pseudo = $pseudo; - } - - public function getPassword(): string - { - return $this->password; - } - - public function setPassword(string $password): void - { - $this->password = $password; - } - - public function getEmail(): string - { - return $this->email; - } - - public function setEmail(string $email): void - { - $this->email = $email; - } - - public function getDate(): string - { - return $this->date; - } - - public function setDate(string $date): void - { - $this->date = $date; - } - - public function isAdmin(): bool - { - return $this->isAdmin; - } - - public function setIsAdmin(bool $isAdmin): void - { - $this->isAdmin = $isAdmin; - } - - public function getImgPrfl(): int - { - return $this->imgPrfl; - } - - public function setImgPrfl(int $imgPrfl): void - { - $this->imgPrfl = $imgPrfl; - } - - /** - * @param int $id - * @param string $pseudo - * @param string $password - * @param string $email - * @param int $imgPrfl - * @param bool $isAdmin - * @param string $date - */ - public function __construct(int $id, string $pseudo, string $password, string $email, int $imgPrfl, bool $isAdmin, string $date) - { - $this->id = $id; - $this->pseudo = $pseudo; - $this->password = $password; - $this->email = $email; - $this->imgPrfl = $imgPrfl; - $this->isAdmin = $isAdmin; - $this->date = $date; - } - - - } - // ============================================ En attente du Model ============================================ - /*$dsn = "pgsql:host=londres;dbname=dblebeaulato"; - $username = "lebeaulato"; - $password = ""; - - $con = new Connection($dsn,$username,$password); - - $query = 'SELECT * FROM Users WHERE id_user=:idUser'; - $con->executeQuery($query, array(':idUser'=>array('U003', PDO::PARAM_STR))); - $result = $con->getResults(); - - $u = new User($result[0]['id_user'],$result[0]['username'], $result[0]['pssword'], '../images/imageProfil.png', $result[0]['email']); - - - - - //UPDATE username User - $query = 'UPDATE Users SET username=:newUsername WHERE id_user=:idUser'; - $con->executeQuery($query, array(':idUser'=>array('U003', PDO::PARAM_STR), ':newUsername'=> array('Hello', PDO::PARAM_STR))); - $queryReponse = 'SELECT username FROM Users WHERE id_user=:idUser'; - - $con->executeQuery($queryReponse, array(':idUser'=>array('U003', PDO::PARAM_STR))); - $result = $con->getResults(); - $u->setUsername($result[0]['username']); - - - //UPDATE email User - $query = 'UPDATE Users SET email=:newEmail WHERE id_user=:idUser'; - $con->executeQuery($query, array(':idUser'=>array('U003', PDO::PARAM_STR), ':newEmail'=> array('hello@gmail.com', PDO::PARAM_STR))); - $queryReponse = 'SELECT email FROM Users WHERE id_user=:idUser'; - - $con->executeQuery($queryReponse, array(':idUser'=>array('U003', PDO::PARAM_STR))); - $result = $con->getResults(); - $u->setEmail($result[0]['email']); - - //UPDATE passwd User - $query = 'UPDATE Users SET pssword=:newPassWd WHERE id_user=:idUser'; - $con->executeQuery($query, array(':idUser'=>array('U003', PDO::PARAM_STR), ':newPassWd'=> array('TestMotDePasssse', PDO::PARAM_STR))); - - $queryReponse = 'SELECT pssword FROM Users WHERE id_user=:idUser'; - $con->executeQuery($queryReponse, array(':idUser'=>array('U003', PDO::PARAM_STR))); - $result = $con->getResults(); - $u->setPasswd($result[0]['pssword']); /*Test*/ - -// ================================================================================================================ - - - - function hidenPassWd(string $passwd){ - if(strlen($passwd) >= 16) return str_repeat('*', 16); - return str_repeat('*', strlen($passwd)); - } -?> diff --git a/src/Gateway/CommentaryGateway.php b/src/Gateway/CommentaryGateway.php index e9d64bd..110850c 100644 --- a/src/Gateway/CommentaryGateway.php +++ b/src/Gateway/CommentaryGateway.php @@ -8,14 +8,28 @@ class CommentaryGateway { $this->co = $co; } + public function firstIdComment():int{ + $query = "Select id_comment from Commentary;"; + $this -> co -> executeQuery($query); + $res = $this -> co -> getResults(); + foreach($res as $r){ + $tab[] = $r["id_comment"]; + } + $id=1; + while(in_array($id,$tab)){$id=$id+1;} + return $id; + } + public function create(string $comment ,string $idUser, int $idQuote) :bool { + $id=$this->firstIdComment(); - $query="INSERT INTO Commentary(quote,users,datec,comment) VALUES(:idQuote, :idUser , CURRENT_DATE,:comment )"; + $query="INSERT INTO Commentary(quote,users,datec,comment,id_comment) VALUES(:idQuote, :idUser , CURRENT_DATE,:comment ,:idComment)"; return $this -> co -> executeQuery($query, array( "comment" => array($comment, PDO::PARAM_STR), "idUser" => array($idUser, PDO::PARAM_STR), - "idQuote" => array($idQuote, PDO::PARAM_INT))); + "idQuote" => array($idQuote, PDO::PARAM_INT), + "idComment" => array($id, PDO::PARAM_INT))); } public function findById(int $id) : array { @@ -27,7 +41,7 @@ class CommentaryGateway { } public function findByQuote(int $id) : array{ - $query="SELECT c.id_comment, c.dateC, c.comment, u.username FROM Commentary c JOIN Users u ON u.id_user = c.users WHERE quote = :idQuote"; + $query="SELECT c.id_comment, c.dateC, c.comment, u.username FROM Commentary c JOIN Users u ON u.id_user = c.users WHERE quote = :idQuote ORDER BY c.datec DESC"; $this -> co -> executeQuery($query, array("idQuote" => array($id,PDO::PARAM_STR))); return $res = $this -> co -> getResults(); } diff --git a/src/Gateway/UserGateway.php b/src/Gateway/UserGateway.php index 72cd15d..c7a2c8f 100644 --- a/src/Gateway/UserGateway.php +++ b/src/Gateway/UserGateway.php @@ -19,21 +19,34 @@ Class UserGateway{ return $this -> con -> getResults(); } - public function insertUser(int $id, string $pseudo, string $email, string $password, bool $isAdmin, int $imgPrfl) : bool { + public function firstIdUser():int{ + $query = "Select id_user from Users;"; + $this -> con -> executeQuery($query); + $res = $this -> con -> getResults(); + foreach($res as $r){ + $tab[] = $r["id_user"]; + } + $id=1; + while(in_array($id,$tab)){$id=$id+1;} + return $id; + } + + public function insertUser(string $pseudo, string $email, string $password, bool $isAdmin, int $imgPrfl) : bool { + $id=$this->firstIdUser(); $query = " - INSERT INTO Users - VALUES (:id, :pseudo, :email, :password, CURRENT_DATE, :isAdmin, :imgPrfl) + INSERT INTO Users(id_user,username,email,password,creation,img) + VALUES (:id, :pseudo, :email, :password, CURRENT_DATE, :imgPrfl); "; return $this -> con -> executeQuery($query, [ ":id" => [$id, PDO::PARAM_INT], ":pseudo" => [$pseudo, PDO::PARAM_STR], ":email" => [$email, PDO::PARAM_STR], ":password" => [$password, PDO::PARAM_STR], - ":isAdmin" => [$isAdmin, PDO::PARAM_INT], ":imgPrfl" => [$imgPrfl, PDO::PARAM_STR] ]); } + public function delete(string $id) : bool{ // supretion user diff --git a/src/Model/UserModel.php b/src/Model/UserModel.php index a6407a9..f82fc7f 100644 --- a/src/Model/UserModel.php +++ b/src/Model/UserModel.php @@ -14,7 +14,7 @@ public function insertUser(string $username,string $email,string $passwd) : bool{ /*global $rep,$image;*/ - return $this->gateway->insertUser($this->getNumberOfUsers() + 1, $username, $email, $passwd, false, 0); + return $this->gateway->insertUser( $username, $email, $passwd, false, 1); } public function getNumberOfUsers() : int @@ -42,10 +42,9 @@ return new UserEntity( $res[0]['id_user'], $res[0]['username'], - $res[0]['pssword'], + $res[0]['password'], $res[0]['email'], - $res[0]['img_prfl'], - $res[0]['is_admin'], + $res[0]['img'], $res[0]['creation'] ); return null; @@ -58,10 +57,9 @@ return new UserEntity( $res[0]['id_user'], $res[0]['username'], - $res[0]['pssword'], + $res[0]['password'], $res[0]['email'], - $res[0]['img_prfl'], - $res[0]['is_admin'], + $res[0]['img'], $res[0]['creation'] ); return null; @@ -74,10 +72,9 @@ return new UserEntity( $res[0]['id_user'], $res[0]['username'], - $res[0]['pssword'], + $res[0]['password'], $res[0]['email'], - $res[0]['img_prfl'], - $res[0]['is_admin'], + $res[0]['img'], $res[0]['creation'] ); return null; diff --git a/vue/login.php b/vue/login.php index 59abf86..24b1333 100644 --- a/vue/login.php +++ b/vue/login.php @@ -9,5 +9,7 @@ )); echo $twig->render('bandeau.html.twig'); - echo $twig->render('login.html.twig'); + echo $twig->render('login.html.twig',array( + 'error' => $errors??null + )); ?> \ No newline at end of file diff --git a/vue/signin.php b/vue/signin.php index efb8cd3..a3cdaca 100644 --- a/vue/signin.php +++ b/vue/signin.php @@ -1,5 +1,4 @@ render('head.html.twig', array( @@ -9,5 +8,7 @@ )); echo $twig->render('bandeau.html.twig'); - echo $twig->render('signin.html'); + echo $twig->render('signin.html.twig',array( + 'error'=>$errors??null) + ); ?> \ No newline at end of file diff --git a/vue/templates/login.html.twig b/vue/templates/login.html.twig index b453775..9cbaad0 100644 --- a/vue/templates/login.html.twig +++ b/vue/templates/login.html.twig @@ -1,33 +1,6 @@ - - -
- - - -