Add: validation

master
Mathilde JEAN 2 years ago
parent 2a7b0e0572
commit 8d270ebbac

@ -5,16 +5,16 @@
if (!isset($usrName)||$usrName=="") { if (!isset($usrName)||$usrName=="") {
$dataVueEreur[] ="Username or password missing"; $dataVueEreur[] ="Username or password missing";
} }
$usrName = Validation::clear_string($usrName); if ($usrName != Validation::clear_string($usrName)){
if($usrName == false){ $dataVueEreur[] = "Forbidden characters";
$dataVueEreur[] = "Sanitizing error"; $usrName="";
} }
if (!isset($mdp)||$mdp=="") { if (!isset($mdp)||$mdp=="") {
$dataVueEreur[] ="Username or password missing"; $dataVueEreur[] ="Username or password missing";
} }
$mdp = Validation::clear_string($mdp); if($mdp != Validation::clear_string($mdp)){
if($mdp == false){ $dataVueEreur[] = "Forbidden characters";
$dataVueEreur[] = "Sanitizing error"; $mdp="";
} }
return $dataVueEreur; return $dataVueEreur;
} }
@ -23,24 +23,23 @@
if (!isset($username)||$username==="") { if (!isset($username)||$username==="") {
$dataVueEreur[] ="All fields are required"; $dataVueEreur[] ="All fields are required";
} }
$_POST['username'] = Validation::clear_string($_POST['username']); if($username != Validation::clear_string($username)){
if($_POST['username'] == false){ $dataVueEreur[] = "Forbidden characters";
$dataVueEreur[] = "Sanitizing error"; $username="";
throw new Exception('sanitizing fail');
} }
if (!isset($pwd1)||$pwd1==="") { if (!isset($pwd1)||$pwd1==="") {
$dataVueEreur[] ="All fields are required"; $dataVueEreur[] ="All fields are required";
} }
$_POST['password'] = Validation::clear_string($_POST['password']); if($pwd1 != Validation::clear_string($pwd1)){
if($_POST['password'] == false){ $dataVueEreur[] = "Forbidden characters";
$dataVueEreur[] = "Sanitizing error"; $pwd1="";
} }
if (!isset($pwd2)||$pwd2==="") { if (!isset($pwd2)||$pwd2==="") {
$dataVueEreur[] ="All fields are required"; $dataVueEreur[] ="All fields are required";
} }
$_POST['confirmpassword'] = Validation::clear_string($_POST['confirmpassword']); if($pwd2 != Validation::clear_string($pwd2)){
if($_POST['confirmpassword'] == false){ $dataVueEreur[] = "Forbidden characters";
$dataVueEreur[] = "Sanitizing error"; $pwd2="";
} }
if($pwd1 !== $pwd2){ if($pwd1 !== $pwd2){
$dataVueEreur[]="Invalid confirmation"; $dataVueEreur[]="Invalid confirmation";
@ -48,15 +47,24 @@
return $dataVueEreur; return $dataVueEreur;
} }
static function val_intitule($dataVueEreur){ static function val_intitule($name, $dataVueEreur){
if (!isset($_POST['name'])||$_POST['name']==="") { if (!isset($name)||$name==="") {
$dataVueEreur[] ="Intitulé manquant"; $dataVueEreur[] ="Intitulé manquant";
throw new Exception('pas d\'intitule');
} }
$_POST['name'] = Validation::clear_string($_POST['name']); if($name != Validation::clear_string($name)){
if($_POST['name'] == false){ $dataVueEreur[] = "Forbidden characters";
$dataVueEreur[] = "Sanitizing error"; $name="";
throw new Exception('sanitizing fail'); }
return $dataVueEreur;
}
static function val_id($id, $dataVueEreur){
if (!isset($id)||$id=""){
$dataVueEreur[] = "Id error";
}
if($id != filter_var($id, FILTER_VALIDATE_INT)){
$dataVueEreur[] = "Id validation error";
$id = 0;
} }
return $dataVueEreur; return $dataVueEreur;
} }

@ -3,7 +3,7 @@
//Prefixe //Prefixe
$rep=__DIR__.'/../'; $rep=__DIR__.'/../';
//BD //BD
$bd['dsn'] = "mysql:host=localhost;port=8888;dbname=dbPhp"; $bd['dsn'] = "mysql:host=localhost;port=8888;dbname=bdPhp";
$bd['user'] = "root"; $bd['user'] = "root";
$bd['pswd'] = "root"; $bd['pswd'] = "root";
//Vues //Vues

@ -84,6 +84,7 @@ class ControleurVisiteur {
public function accessListInfos($arrayErrorViews){ public function accessListInfos($arrayErrorViews){
global $rep,$vues,$dataView; global $rep,$vues,$dataView;
$idListe=$_POST['liste']; $idListe=$_POST['liste'];
$arrayErrorViews = Validation::val_id($idListe, $arrayErrorViews);
$model = new ListeModel(); $model = new ListeModel();
$dataView = $model->pullListById($idListe); $dataView = $model->pullListById($idListe);
require($rep.$vues['infosListe']); require($rep.$vues['infosListe']);
@ -91,9 +92,10 @@ class ControleurVisiteur {
public function addTache($arrayErrorViews){ public function addTache($arrayErrorViews){
global $rep,$vues,$dataView; global $rep,$vues,$dataView;
$arrayErrorViews = Validation::val_intitule($arrayErrorViews);
$nom=$_POST['name']; $nom=$_POST['name'];
$idListe=$_POST['liste']; $idListe=$_POST['liste'];
$arrayErrorViews = Validation::val_intitule($name, $arrayErrorViews);
$arrayErrorViews = Validation::val_id($idListe, $arrayErrorViews);
$model = new ListeModel(); $model = new ListeModel();
$model->addTache($nom,$idListe); $model->addTache($nom,$idListe);
$_REQUEST['action']="accessListInfos"; $_REQUEST['action']="accessListInfos";
@ -103,6 +105,7 @@ class ControleurVisiteur {
public function delTache($arrayErrorViews){ public function delTache($arrayErrorViews){
global $rep,$vues,$dataView; global $rep,$vues,$dataView;
$idTache=$_POST['tache']; $idTache=$_POST['tache'];
$arrayErrorViews = Validation::val_id($idTache, $arrayErrorViews);
$model= new ListeModel(); $model= new ListeModel();
$model->delTache($idTache); $model->delTache($idTache);
$_REQUEST['action']="accessListInfos"; $_REQUEST['action']="accessListInfos";
@ -112,6 +115,7 @@ class ControleurVisiteur {
public function changeCompletedTache($arrayErrorViews){ public function changeCompletedTache($arrayErrorViews){
global $rep,$vues,$dataView; global $rep,$vues,$dataView;
$idTache=$_POST['tache']; $idTache=$_POST['tache'];
$arrayErrorViews = Validation::val_id($idTache, $arrayErrorViews);
$model = new ListeModel(); $model = new ListeModel();
$model->changeCompletedTache($idTache); $model->changeCompletedTache($idTache);
$_REQUEST['action']="accessListInfos"; $_REQUEST['action']="accessListInfos";
@ -185,6 +189,7 @@ class ControleurVisiteur {
public function delListe(array $vues_erreur){ public function delListe(array $vues_erreur){
global $rep, $vues; global $rep, $vues;
$idListe=$_POST['liste']; $idListe=$_POST['liste'];
$arrayErrorViews = Validation::val_id($idListe, $arrayErrorViews);
$model = new ListeModel(); $model = new ListeModel();
$model->delListe($idListe); $model->delListe($idListe);
$_REQUEST['action']=null; $_REQUEST['action']=null;

Loading…
Cancel
Save