fix je suis débile 2

php
Anthony RICHARD 1 year ago
parent 093ccefa98
commit 1eb6629cd1

@ -9,9 +9,7 @@ class Validation
public static function val_action($action): string { public static function val_action($action): string {
$safeAction = htmlspecialchars($action, ENT_QUOTES); $safeAction = htmlspecialchars($action, ENT_QUOTES);
if (!isset($action)) if ($safeAction != $action)
throw new \Exception('pas d\'action');
else if ($safeAction != $action)
throw new \Exception("tentative d'injection sql détectée"); throw new \Exception("tentative d'injection sql détectée");
else return $safeAction; else return $safeAction;
} }

@ -13,7 +13,7 @@ class AdminController
global $twig; global $twig;
try { try {
$action = Validation::val_action($_REQUEST['action']); $action = Validation::val_action($_REQUEST['action'] ?? null);
switch($action) { switch($action) {
case 'showAllUsers': case 'showAllUsers':

@ -1,81 +0,0 @@
<?php
namespace controleur;
class ControleurTmp
{
public function __construct()
{
global $twig; // nécessaire pour utiliser variables globales
// on démarre ou reprend la session pas utilisée ici
session_start();
//debut
//on initialise un tableau d'erreur
$dVueEreur = [];
try {
$action = $_REQUEST['action'] ?? null;
switch($action) {
//pas d'action, on réinitialise 1er appel
case null:
$this->Reinit();
break;
case 'validationFormulaire':
$this->ValidationFormulaire($dVueEreur);
break;
//mauvaise action
default:
$dVueEreur[] = "Erreur d'appel php";
echo $twig->render('vuephp1.html', ['dVueEreur' => $dVueEreur]);
break;
}
} catch (\PDOException $e) {
//si erreur BD, pas le cas ici
$dVueEreur[] = 'Erreur inattendue!!! ';
} catch (\Exception $e2) {
$dVueEreur[] = 'Erreur inattendue!!! ';
echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]);
}
//fin
exit(0);
}//fin constructeur
public function Reinit()
{
global $twig; // nécessaire pour utiliser variables globales
$dVue = [
'nom' => '',
'age' => 0,
];
echo $twig->render('vuephp1.html', [
'dVue' => $dVue
]);
}
public function ValidationFormulaire(array $dVueEreur)
{
global $twig; // nécessaire pour utiliser variables globales
//si exception, ca remonte !!!
$nom = $_POST['txtNom']; // txtNom = nom du champ texte dans le formulaire
$age = $_POST['txtAge'];
\config\Validation::val_form($nom, $age, $dVueEreur);
$model = new \modeles\Simplemodel();
$data = $model->get_data();
$dVue = [
'nom' => $nom,
'age' => $age,
'data' => $data,
];
echo $twig->render('vuephp1.html', ['dVue' => $dVue, 'dVueEreur' => $dVueEreur]);
}
}//fin class

@ -36,7 +36,7 @@ class FrontController
$dVueEreur = array(); $dVueEreur = array();
try { try {
$action = Validation::val_action($_REQUEST['action']); $action = Validation::val_action($_REQUEST['action'] ?? null);
switch ($action) { switch ($action) {
case null: case null:

@ -12,7 +12,7 @@ class StudentController
global $twig; global $twig;
try { try {
$action = $_REQUEST['action'] ?? null; $action = Validation::val_action($_REQUEST['action'] ?? null);
switch ($action) { switch ($action) {
case 'allVocab': case 'allVocab':
$this->affAllVocab(); $this->affAllVocab();

@ -1,6 +1,7 @@
<?php <?php
namespace controller; namespace controller;
use config\Validation;
use model\MdlTeacher; use model\MdlTeacher;
use Exception; use Exception;
@ -11,7 +12,7 @@ class TeacherController
global $twig; global $twig;
try { try {
$action = $_REQUEST['action'] ?? null; $action = Validation::val_action($_REQUEST['action'] ?? null);
switch ($action) { switch ($action) {
case 'getAllStudent': case 'getAllStudent':

Loading…
Cancel
Save