From 62924b327d945996b336409883fb985cce76c53f Mon Sep 17 00:00:00 2001 From: Anna BOUDOUL Date: Thu, 22 Dec 2022 21:42:03 +0100 Subject: [PATCH 1/8] Validation start --- config/Validation.php | 33 +++++++++++++++++++++++++++++++++ controller/FrontCtrl.php | 5 +---- index.php | 3 +-- model/TaskModel.php | 1 + model/UserModel.php | 22 +++++++++++++++++----- 5 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 config/Validation.php diff --git a/config/Validation.php b/config/Validation.php new file mode 100644 index 0000000..030adde --- /dev/null +++ b/config/Validation.php @@ -0,0 +1,33 @@ + \ No newline at end of file diff --git a/controller/FrontCtrl.php b/controller/FrontCtrl.php index b6951e2..f072dd9 100644 --- a/controller/FrontCtrl.php +++ b/controller/FrontCtrl.php @@ -13,10 +13,7 @@ class FrontCtrl $this->action_User = array('deconnexion','loadListePriv','newListPrivate'); try{ $this->isUser = $this->usrMdl->isConnected(); // cette fonction retourne quoi? - if(isset($_REQUEST['action'])) - $action = $_REQUEST['action']; - else - $action = null; + $action = $_REQUEST['action'] ?? null; if(($i = array_search($action,$this->action_User)) !== false){ # si action dans la liste d'actions user if(!$this->isUser){ # si pas conncter diff --git a/index.php b/index.php index cdc44cb..833ab83 100644 --- a/index.php +++ b/index.php @@ -1,10 +1,9 @@ diff --git a/model/TaskModel.php b/model/TaskModel.php index c0b05ec..1a63606 100644 --- a/model/TaskModel.php +++ b/model/TaskModel.php @@ -43,6 +43,7 @@ class TaskModel /* LIST FUNCTIONS */ public function addList($nom,$owner="",$dc=0,$id=0) { + Validation::val_form_texte($owner, $TMessage); $l = new ListTask($nom,$owner,$dc); $this->gtw->insertL($l); // retourne quoi? con->lastInsertId() ?? diff --git a/model/UserModel.php b/model/UserModel.php index cdbddd4..5f2a3ae 100644 --- a/model/UserModel.php +++ b/model/UserModel.php @@ -1,6 +1,7 @@ gat->findUser($login, $mdp); if(!isset($result)) echo 'not set works'; - // if (isset($result)) - // { - // $_SESSION['login'] = $result; - // } + else + { + $_SESSION['login'] = $result; + } } function deconnexion(){ @@ -25,7 +28,8 @@ $_SESSION = array(); } - function isConnected(){ //teste rôle dans la session, retourne instance d’objet ou booleen + function isConnected(){ //teste rôle dans la session, retourne instance d’objet ou booleen + Validation::val_form_texte($_SESSION['login'], $TMessage); if(isset($_SESSION['login'])){ return true; } else { @@ -34,20 +38,26 @@ } function ajouter($login, $mdp){ + Validation::val_form_texte($login, $TMessage); + Validation::val_form_mdp($mdp, $TMessage); $user = $this->findByLogin($login); if (empty($user)) $this->gat->create($login, $mdp); } function supprimer($login){ + Validation::val_form_texte($login, $TMessage); $this->gat->delete($login); } function modifMdp($login, $mdp){ + Validation::val_form_texte($login, $TMessage); + Validation::val_form_mdp($mdp, $TMessage); $this->gat->updateMdp($login, $mdp); } function findByLogin($login){ + Validation::val_form_texte($login, $TMessage); $user = null; if ($login !== " " && $login != null ) { @@ -60,6 +70,8 @@ } function modifLogin($oldLogin, $newLogin){ + Validation::val_form_texte($oldLogin, $TMessage); + Validation::val_form_texte($newLogin, $TMessage); $user = $this->findByLogin($oldLogin); if (empty($user)) $this->gat->updateLogin($oldLogin, $newLogin); From f04cfc060b9abc62edb9211c2d431b70c2542053 Mon Sep 17 00:00:00 2001 From: Anna BOUDOUL Date: Thu, 22 Dec 2022 21:55:10 +0100 Subject: [PATCH 2/8] Validation correction --- config/Validation.php | 12 ++++++------ controller/UserCtrl.php | 40 +++++++++++++++++++++----------------- controller/VisitorCtrl.php | 2 +- model/UserModel.php | 1 + 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/config/Validation.php b/config/Validation.php index 030adde..97aa788 100644 --- a/config/Validation.php +++ b/config/Validation.php @@ -2,29 +2,29 @@ class Validation { - static function val_form_texte(string &$texte, array &$TMessage) { + static function val_form_texte(&$texte, &$TMessage) { if (!isset($texte)||$texte=="") { - $TMessage[] ="champs vide"; + $TMessage[] ="Empty fields"; $texte=""; } if ($texte != filter_var($texte, FILTER_SANITIZE_STRING)) { - $TMessage[] ="testative d'injection de code (attaque sécurité)"; + $TMessage[]="Attempt to inject code (security attack)"; $texte=""; } } - static function val_form_mdp(string &$mdp, array &$TMessage) { + static function val_form_mdp(&$mdp, &$TMessage) { if (!isset($mdp)||$mdp=="") { - $TMessage[] ="pas de mdp"; + $TMessage[] ="Password not specified"; $mdp=""; } if ($mdp != filter_var($mdp, FILTER_SANITIZE_SPECIAL_CHARS)) { - $TMessage[] ="Le mot de passe ne doit pas contenir de caractères spéciaux"; + $TMessage[] ="Password must not contain special characters"; $mdp=""; } diff --git a/controller/UserCtrl.php b/controller/UserCtrl.php index 1dfa5c6..b488c7c 100644 --- a/controller/UserCtrl.php +++ b/controller/UserCtrl.php @@ -12,27 +12,31 @@ class UserCtrl $this->con = $con; $this->userModel = new UserModel($this->con); $this->taskModel = new TaskModel($this->con); - // try{ - // $action=$_REQUEST['action']; - // switch($action){ + try{ + $action=$_REQUEST['action']; + switch($action){ - // // voir les listes privees - // case 'voirListePriv': - // $this->loadListePriv(); - // break; + // voir les listes privees + case 'voirListePriv': + $this->loadListePriv(); + break; - // // ajouter une liste privee - // case 'creerListePriv': - // $this->newListPrivate(); - // break; - // case 'deconnecter': - // $this->deconnexion(); - // break; + // ajouter une liste privee + case 'creerListePriv': + $this->newListPrivate(); + break; + case 'deconnecter': + $this->deconnexion(); + break; + default: + $TMessage[] = 'Unexpected error'; + require($rep.$vues['']); + break; - // } - // } catch(Exception $e) { - // require("../view/erreur.php"); - // } + } + } catch(Exception $e) { + require("../view/erreur.php"); + } } public function loadListePriv(){ diff --git a/controller/VisitorCtrl.php b/controller/VisitorCtrl.php index fa61be4..fa68399 100644 --- a/controller/VisitorCtrl.php +++ b/controller/VisitorCtrl.php @@ -71,7 +71,7 @@ class VisitorCtrl default: # - $dvueErreur[] = 'Erreur inattendue'; + $TMessage[] = 'Unexpected error'; require($rep.$vues['']); break; } diff --git a/model/UserModel.php b/model/UserModel.php index 5f2a3ae..9123dd6 100644 --- a/model/UserModel.php +++ b/model/UserModel.php @@ -1,6 +1,7 @@ Date: Thu, 22 Dec 2022 22:16:41 +0100 Subject: [PATCH 3/8] Merging error left corrected --- controller/VisitorCtrl.php | 2 +- index.php | 2 +- view/erreur.php | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 view/erreur.php diff --git a/controller/VisitorCtrl.php b/controller/VisitorCtrl.php index 048d9ce..68efd4b 100644 --- a/controller/VisitorCtrl.php +++ b/controller/VisitorCtrl.php @@ -72,7 +72,7 @@ class VisitorCtrl default: # $TMessage[] = 'Unexpected error'; - require($rep.$vues['']); + require("view/erreur.php"); break; } diff --git a/index.php b/index.php index 833ab83..18e9f7d 100644 --- a/index.php +++ b/index.php @@ -1,8 +1,8 @@ diff --git a/view/erreur.php b/view/erreur.php new file mode 100644 index 0000000..447657e --- /dev/null +++ b/view/erreur.php @@ -0,0 +1,5 @@ +"; + } +?> \ No newline at end of file From aaeb0ab80d8ee376e826e2c2b750b02a866d6e96 Mon Sep 17 00:00:00 2001 From: Anna BOUDOUL Date: Thu, 22 Dec 2022 22:24:23 +0100 Subject: [PATCH 4/8] Error view --- view/erreur.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/view/erreur.php b/view/erreur.php index 447657e..5998524 100644 --- a/view/erreur.php +++ b/view/erreur.php @@ -1,5 +1,18 @@ -"; - } -?> \ No newline at end of file + + + + + + + + + + Error!' . $err . ""; + } + ?> + + \ No newline at end of file From 770cc345af064f14137a619b28853ed80299f6c7 Mon Sep 17 00:00:00 2001 From: Anna BOUDOUL Date: Thu, 22 Dec 2022 22:41:05 +0100 Subject: [PATCH 5/8] TabVues --- config/config.php | 9 +++++++++ controller/FrontCtrl.php | 2 +- controller/UserCtrl.php | 8 ++++---- controller/VisitorCtrl.php | 12 ++++++------ 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/config/config.php b/config/config.php index 99c30de..69a4402 100644 --- a/config/config.php +++ b/config/config.php @@ -7,4 +7,13 @@ $con = new Connection('mysql:host=localhost;dbname=dbanboudoul', 'anboudoul', 'mdpMYSQL'); $TMessage = array(); + + $TabVues = array( + "erreur" => "view/erreur.php", + "home" => "view/home.php", + "connection" => "view/connection.php", + "register" => "view/register.php", + "newList" => "view/newList.php", + "liste" => "view/liste.php", + ) ?> \ No newline at end of file diff --git a/controller/FrontCtrl.php b/controller/FrontCtrl.php index f072dd9..769327d 100644 --- a/controller/FrontCtrl.php +++ b/controller/FrontCtrl.php @@ -33,7 +33,7 @@ class FrontCtrl $visitCtrl = new VisitorCtrl($con,$this->isUser); } } catch (Exception $e){ // verifier si catch bon - require("../view/erreur.php"); + require($TabVues["erreur"]); } } } diff --git a/controller/UserCtrl.php b/controller/UserCtrl.php index b488c7c..9d4f000 100644 --- a/controller/UserCtrl.php +++ b/controller/UserCtrl.php @@ -30,12 +30,12 @@ class UserCtrl break; default: $TMessage[] = 'Unexpected error'; - require($rep.$vues['']); + require($TabVues["erreur"]); break; } } catch(Exception $e) { - require("../view/erreur.php"); + require($TabVues["erreur"]); } } @@ -44,7 +44,7 @@ class UserCtrl // $TabList[] = new ListTask(0, "Projet PHP"); // $TabList[] = new ListTask(1, "Projet Blazor"); $TabList = $this->taskModel->loadPrivateLists($_SESSION['login']); - require("../view/liste.php"); + require($TabVues["liste"]); } public function newListPrivate(){ @@ -56,7 +56,7 @@ class UserCtrl function loadHome(){ $user = false; $public_lists = $this->taskModel->loadPublicLists(); - require("../view/home.php"); + require($TabVues["home"]); } public function deconnexion(){ diff --git a/controller/VisitorCtrl.php b/controller/VisitorCtrl.php index 68efd4b..5d177dd 100644 --- a/controller/VisitorCtrl.php +++ b/controller/VisitorCtrl.php @@ -72,23 +72,23 @@ class VisitorCtrl default: # $TMessage[] = 'Unexpected error'; - require("view/erreur.php"); + require($TabVues["erreur"]); break; } } catch (Exception $e) { - require("view/erreur.php"); + require($TabVues["erreur"]); } } function loadHome(){ $public_lists = $this->taskModel->loadPublicLists(); $user = $this->isUser; - require("view/home.php"); + require($TabVues["home"]); } function go_connection(){ $user = $this->isUser; - require("view/connection.php"); + require($TabVues["connection"]); } function connection(){ @@ -97,7 +97,7 @@ class VisitorCtrl function go_register(){ $user = $this->isUser; - require("view/register.php"); + require($TabVues["register"]); } function register(){ @@ -106,7 +106,7 @@ class VisitorCtrl function go_list(){ $user = $this->isUser; - require("view/newList.php"); + require($TabVues["newList"]); } function makeList(){ From 15bc35ab0ab9c3cd6466e81e5de4af174ce0628b Mon Sep 17 00:00:00 2001 From: Anna BOUDOUL Date: Thu, 22 Dec 2022 23:21:42 +0100 Subject: [PATCH 6/8] correcting bugs TabVues --- config/config.php | 16 ++++++++-------- controller/FrontCtrl.php | 11 +++++++---- controller/UserCtrl.php | 12 +++++++----- controller/VisitorCtrl.php | 17 ++++++++++------- index.php | 8 ++++---- 5 files changed, 36 insertions(+), 28 deletions(-) diff --git a/config/config.php b/config/config.php index 69a4402..d192ac5 100644 --- a/config/config.php +++ b/config/config.php @@ -8,12 +8,12 @@ $TMessage = array(); - $TabVues = array( - "erreur" => "view/erreur.php", - "home" => "view/home.php", - "connection" => "view/connection.php", - "register" => "view/register.php", - "newList" => "view/newList.php", - "liste" => "view/liste.php", - ) + $TabVues = array(); + $TabVues["erreur"] = "view/erreur.php"; + $TabVues["home"] = "view/home.php"; + $TabVues["connection"] = "view/connection.php"; + $TabVues["register"] = "view/register.php"; + $TabVues["newList"] = "view/newList.php"; + $TabVues["liste"] = "view/liste.php"; + ?> \ No newline at end of file diff --git a/controller/FrontCtrl.php b/controller/FrontCtrl.php index 769327d..c5040b8 100644 --- a/controller/FrontCtrl.php +++ b/controller/FrontCtrl.php @@ -1,4 +1,5 @@ TabVues = $TabVues; $this->usrMdl = new UserModel($con); $this->action_User = array('deconnexion','loadListePriv','newListPrivate'); try{ @@ -19,7 +22,7 @@ class FrontCtrl if(!$this->isUser){ # si pas conncter # appel controlleur visiteur avec action connecter require("VisitorCtrl.php"); - $visitCtrl = new VisitorCtrl($con); + $visitCtrl = new VisitorCtrl($con, $this->TabVues); $visitCtrl->goconnexion(); } else { # sinon # handle action avec controlleur user @@ -30,10 +33,10 @@ class FrontCtrl } else { # sinon forcement action visiteur # appel controlleur visiteur avec l'action require("VisitorCtrl.php"); - $visitCtrl = new VisitorCtrl($con,$this->isUser); + $visitCtrl = new VisitorCtrl($con, $this->TabVues, $this->isUser); } } catch (Exception $e){ // verifier si catch bon - require($TabVues["erreur"]); + require($this->TabVues["erreur"]); } } } diff --git a/controller/UserCtrl.php b/controller/UserCtrl.php index 9d4f000..f7150f9 100644 --- a/controller/UserCtrl.php +++ b/controller/UserCtrl.php @@ -7,8 +7,10 @@ class UserCtrl private $con; private $taskModel; private $userModel; + private $TabVues; - public function __construct(Connection $con){ + public function __construct(Connection $con, $TabVues){ + $this->TabVues = $TabVues; $this->con = $con; $this->userModel = new UserModel($this->con); $this->taskModel = new TaskModel($this->con); @@ -30,12 +32,12 @@ class UserCtrl break; default: $TMessage[] = 'Unexpected error'; - require($TabVues["erreur"]); + require($this->TabVues["erreur"]); break; } } catch(Exception $e) { - require($TabVues["erreur"]); + require($this->TabVues["erreur"]); } } @@ -44,7 +46,7 @@ class UserCtrl // $TabList[] = new ListTask(0, "Projet PHP"); // $TabList[] = new ListTask(1, "Projet Blazor"); $TabList = $this->taskModel->loadPrivateLists($_SESSION['login']); - require($TabVues["liste"]); + require($this->TabVues["liste"]); } public function newListPrivate(){ @@ -56,7 +58,7 @@ class UserCtrl function loadHome(){ $user = false; $public_lists = $this->taskModel->loadPublicLists(); - require($TabVues["home"]); + require($this->TabVues["home"]); } public function deconnexion(){ diff --git a/controller/VisitorCtrl.php b/controller/VisitorCtrl.php index 5d177dd..8dabfda 100644 --- a/controller/VisitorCtrl.php +++ b/controller/VisitorCtrl.php @@ -1,12 +1,15 @@ TabVues = $TabVues; $this->isUser = $isUser; $dvueErreur = array(); $this->taskModel = new TaskModel($con); @@ -72,23 +75,23 @@ class VisitorCtrl default: # $TMessage[] = 'Unexpected error'; - require($TabVues["erreur"]); + require($this->TabVues["erreur"]); break; } } catch (Exception $e) { - require($TabVues["erreur"]); + require($this->TabVues["erreur"]); } } function loadHome(){ $public_lists = $this->taskModel->loadPublicLists(); $user = $this->isUser; - require($TabVues["home"]); + require($this->TabVues["home"]); } function go_connection(){ $user = $this->isUser; - require($TabVues["connection"]); + require($this->TabVues["connection"]); } function connection(){ @@ -97,7 +100,7 @@ class VisitorCtrl function go_register(){ $user = $this->isUser; - require($TabVues["register"]); + require($this->TabVues["register"]); } function register(){ @@ -106,7 +109,7 @@ class VisitorCtrl function go_list(){ $user = $this->isUser; - require($TabVues["newList"]); + require($this->TabVues["newList"]); } function makeList(){ diff --git a/index.php b/index.php index 18e9f7d..8cec805 100644 --- a/index.php +++ b/index.php @@ -1,9 +1,9 @@ From fc60b17097d49f55ecfebf8283489a9998fb7f48 Mon Sep 17 00:00:00 2001 From: Anna BOUDOUL Date: Thu, 22 Dec 2022 23:50:22 +0100 Subject: [PATCH 7/8] View about --- view/about.php | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 view/about.php diff --git a/view/about.php b/view/about.php new file mode 100644 index 0000000..cfafb0d --- /dev/null +++ b/view/about.php @@ -0,0 +1,74 @@ + + + + + + + + + + + +
+ + + +
+ + + +
+
+
+
+
+
+

2Do

+

A PHP project

+

+ A little PHP project realised by two french students studying Computer Science at the IUT of + Clermont Auvergne in France. The main goal of this project was to create a little To Do List + using the PHP language. We hope that you will find it useful. +

+
+
+
+
+
+ +
+
+ + + + + \ No newline at end of file From db3e5db096077c0111f4a615c06da58ba2cfd00f Mon Sep 17 00:00:00 2001 From: Anna BOUDOUL Date: Fri, 23 Dec 2022 00:41:34 +0100 Subject: [PATCH 8/8] view task --- view/newTask.php | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 view/newTask.php diff --git a/view/newTask.php b/view/newTask.php new file mode 100644 index 0000000..03e3436 --- /dev/null +++ b/view/newTask.php @@ -0,0 +1,87 @@ + + + + + + + + + + + +
+ + + +
+ + + +
+

New Task

+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + + +
+
+
+
+ + + + + \ No newline at end of file