pull/6/head
Roxane ROSSETTO 1 year ago
commit 758f6eeb31

@ -2,10 +2,17 @@
<module type="WEB_MODULE" version="4"> <module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/mvc_PSR4_twig/config" isTestSource="false" packagePrefix="config\" />
<sourceFolder url="file://$MODULE_DIR$/mvc_PSR4_twig/controleur" isTestSource="false" packagePrefix="controleur\" />
<sourceFolder url="file://$MODULE_DIR$/mvc_PSR4_twig/metier" isTestSource="false" packagePrefix="modeles\" />
<excludeFolder url="file://$MODULE_DIR$/vendor/composer" /> <excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/twig/twig" /> <excludeFolder url="file://$MODULE_DIR$/vendor/twig/twig" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-mbstring" /> <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-mbstring" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-ctype" /> <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-ctype" />
<excludeFolder url="file://$MODULE_DIR$/mvc_PSR4_twig/vendor/composer" />
<excludeFolder url="file://$MODULE_DIR$/mvc_PSR4_twig/vendor/symfony/polyfill-ctype" />
<excludeFolder url="file://$MODULE_DIR$/mvc_PSR4_twig/vendor/symfony/polyfill-mbstring" />
<excludeFolder url="file://$MODULE_DIR$/mvc_PSR4_twig/vendor/twig/twig" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />

@ -1,14 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="MessDetectorOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PHPCSFixerOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PHPCodeSnifferOptionsConfiguration">
<option name="highlightLevel" value="WARNING" />
<option name="transferred" value="true" />
</component>
<component name="PhpIncludePathManager"> <component name="PhpIncludePathManager">
<include_path> <include_path>
<path value="$PROJECT_DIR$/vendor/composer" /> <path value="$PROJECT_DIR$/vendor/composer" />
<path value="$PROJECT_DIR$/vendor/twig/twig" /> <path value="$PROJECT_DIR$/vendor/twig/twig" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-mbstring" /> <path value="$PROJECT_DIR$/vendor/symfony/polyfill-mbstring" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-ctype" /> <path value="$PROJECT_DIR$/vendor/symfony/polyfill-ctype" />
<path value="$PROJECT_DIR$/mvc_PSR4_twig/vendor/symfony/polyfill-mbstring" />
<path value="$PROJECT_DIR$/mvc_PSR4_twig/vendor/symfony/polyfill-ctype" />
<path value="$PROJECT_DIR$/mvc_PSR4_twig/vendor/composer" />
<path value="$PROJECT_DIR$/mvc_PSR4_twig/vendor/twig/twig" />
</include_path> </include_path>
</component> </component>
<component name="PhpProjectSharedConfiguration" php_language_level="8.0"> <component name="PhpProjectSharedConfiguration" php_language_level="8.0">
<option name="suggestChangeDefaultLanguageLevel" value="false" /> <option name="suggestChangeDefaultLanguageLevel" value="false" />
</component> </component>
<component name="PhpStanOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PsalmOptionsConfiguration">
<option name="transferred" value="true" />
</component>
</project> </project>

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/mvc_PSR4_twig.iml" filepath="$PROJECT_DIR$/.idea/mvc_PSR4_twig.iml" />
</modules>
</component>
</project>

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/config" isTestSource="false" packagePrefix="config\" />
<sourceFolder url="file://$MODULE_DIR$/controleur" isTestSource="false" packagePrefix="controleur\" />
<sourceFolder url="file://$MODULE_DIR$/metier" isTestSource="false" packagePrefix="modeles\" />
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-ctype" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-mbstring" />
<excludeFolder url="file://$MODULE_DIR$/vendor/twig/twig" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PhpIncludePathManager">
<include_path>
<path value="$PROJECT_DIR$/vendor/composer" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-ctype" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-mbstring" />
<path value="$PROJECT_DIR$/vendor/twig/twig" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="8.0">
<option name="suggestChangeDefaultLanguageLevel" value="false" />
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

@ -0,0 +1,25 @@
<?php
namespace DAL;
use App\modeles\Article;
use PDO;
class ArticleGateway
{
private $con;
/**
* @param $con
*/
public function __construct($con)
{
$this->con = $con;
}
public function getAllArticles():array
{
$query = 'SELECT * FROM Article;';
$this->con->executeQuery($query, array());
return $this->con->getResults();
}
}

@ -1,6 +1,6 @@
<?php <?php
namespace modeles; namespace DAL;
use PDO; use PDO;

@ -1,6 +1,6 @@
<?php <?php
namespace modeles; namespace DAL;
use PDO; use PDO;

@ -7,7 +7,7 @@
"psr-4": { "psr-4": {
"controleur\\": "controleur/", "controleur\\": "controleur/",
"config\\": "config/", "config\\": "config/",
"modeles\\": "modeles/" "modeles\\": "metier/"
} }
} }
} }

@ -1,34 +1,34 @@
<?php <?php
namespace config; namespace config;
class Validation class Validation
{ {
public static function val_action($action) public static function val_action($action)
{ {
if (!isset($action)) { if (!isset($action)) {
throw new \Exception('pas d\'action'); throw new \Exception('pas d\'action');
//on pourrait aussi utiliser //on pourrait aussi utiliser
//$action = $_GET['action'] ?? 'no'; //$action = $_GET['action'] ?? 'no';
// This is equivalent to: // This is equivalent to:
//$action = if (isset($_GET['action'])) $action=$_GET['action'] else $action='no'; //$action = if (isset($_GET['action'])) $action=$_GET['action'] else $action='no';
} }
} }
public static function val_form(string &$nom, string &$age, &$dVueEreur) public static function val_form(string &$nom, string &$age, &$dVueEreur)
{ {
if (!isset($nom) || $nom == '') { if (!isset($nom) || $nom == '') {
$dVueEreur[] = 'pas de nom'; $dVueEreur[] = 'pas de nom';
$nom = ''; $nom = '';
} }
if ( strlen(htmlspecialchars($nom, ENT_QUOTES)) != strlen($nom) ) { if ( strlen(htmlspecialchars($nom, ENT_QUOTES)) != strlen($nom) ) {
$dVueEreur[] = "testative d'injection de code (attaque sécurité)"; $dVueEreur[] = "testative d'injection de code (attaque sécurité)";
$nom = ''; $nom = '';
} }
if (!isset($age) || $age == '' || !filter_var($age, FILTER_VALIDATE_INT)) { if (!isset($age) || $age == '' || !filter_var($age, FILTER_VALIDATE_INT)) {
$dVueEreur[] = "pas d'age "; $dVueEreur[] = "pas d'age ";
$age = 0; $age = 0;
} }
} }
} }

@ -1,14 +1,14 @@
<?php <?php
//gen //gen
$rep = __DIR__ . '/../'; $rep = __DIR__ . '/../';
// liste des modules à inclure // liste des modules à inclure
//$dConfig['includes']= array('controleur/Validation.php'); //$dConfig['includes']= array('controleur/Validation.php');
//BD //BD
$base = 'sasa'; $base = 'sasa';
$login = ''; $login = '';
$mdp = ''; $mdp = '';

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

@ -1,16 +1,16 @@
<?php <?php
//chargement config //chargement config
require_once __DIR__ . '/config/config.php'; require_once __DIR__ . '/config/config.php';
require __DIR__ . '/vendor/autoload.php'; require __DIR__ . '/vendor/autoload.php';
use controleur\Controleur; use controleur\Controleur;
//twig //twig
$loader = new \Twig\Loader\FilesystemLoader('templates'); $loader = new \Twig\Loader\FilesystemLoader('templates');
$twig = new \Twig\Environment($loader, [ $twig = new \Twig\Environment($loader, [
'cache' => 'cache', 'cache' => false,
]); ]);
$cont = new Controleur(); $cont = new Controleur();

@ -1,127 +1,118 @@
<?php <?php
namespace modeles; namespace metier;
class Article class Article
{ {
private int $id;
private string $title; private string $title;
private string $date; private string $date;
private string $description; private string $description;
private string $guid; private string $guid;
private string $link; private string $link;
private string $mediaContent; private string $mediaContent;
private int $provenance;
/** /**
* @param int $id
* @param string $title * @param string $title
* @param string $date * @param string $date
* @param string $description * @param string $description
* @param string $guid * @param string $guid
* @param string $link * @param string $link
* @param string $mediaContent * @param string $mediaContent
* @param int $provenance
*/ */
public function __construct(string $title, string $date, string $description, string $guid, string $link, string $mediaContent) public function __construct(int $id, string $title, string $date, string $description, string $guid, string $link, string $mediaContent, int $provenance)
{ {
$this->id = $id;
$this->title = $title; $this->title = $title;
$this->date = $date; $this->date = $date;
$this->description = $description; $this->description = $description;
$this->guid = $guid; $this->guid = $guid;
$this->link = $link; $this->link = $link;
$this->mediaContent = $mediaContent; $this->mediaContent = $mediaContent;
$this->provenance = $provenance;
}
public function getId(): int
{
return $this->id;
}
public function setId(int $id): void
{
$this->id = $id;
} }
/**
* @return string
*/
public function getTitle(): string public function getTitle(): string
{ {
return $this->title; return $this->title;
} }
/**
* @param string $title
*/
public function setTitle(string $title): void public function setTitle(string $title): void
{ {
$this->title = $title; $this->title = $title;
} }
/**
* @return string
*/
public function getDate(): string public function getDate(): string
{ {
return $this->date; return $this->date;
} }
/**
* @param string $date
*/
public function setDate(string $date): void public function setDate(string $date): void
{ {
$this->date = $date; $this->date = $date;
} }
/**
* @return string
*/
public function getDescription(): string public function getDescription(): string
{ {
return $this->description; return $this->description;
} }
/**
* @param string $description
*/
public function setDescription(string $description): void public function setDescription(string $description): void
{ {
$this->description = $description; $this->description = $description;
} }
/**
* @return string
*/
public function getGuid(): string public function getGuid(): string
{ {
return $this->guid; return $this->guid;
} }
/**
* @param string $guid
*/
public function setGuid(string $guid): void public function setGuid(string $guid): void
{ {
$this->guid = $guid; $this->guid = $guid;
} }
/**
* @return string
*/
public function getLink(): string public function getLink(): string
{ {
return $this->link; return $this->link;
} }
/**
* @param string $link
*/
public function setLink(string $link): void public function setLink(string $link): void
{ {
$this->link = $link; $this->link = $link;
} }
/**
* @return string
*/
public function getMediaContent(): string public function getMediaContent(): string
{ {
return $this->mediaContent; return $this->mediaContent;
} }
/**
* @param string $mediaContent
*/
public function setMediaContent(string $mediaContent): void public function setMediaContent(string $mediaContent): void
{ {
$this->mediaContent = $mediaContent; $this->mediaContent = $mediaContent;
} }
public function getProvenance(): int
{
return $this->provenance;
}
public function setProvenance(int $provenance): void
{
$this->provenance = $provenance;
}
} }

@ -1,6 +1,6 @@
<?php <?php
namespace modeles; namespace metier;
class Flux class Flux
{ {

@ -0,0 +1,18 @@
<?php
namespace model;
use DAL;
use metier;
class ArticleModel
{
public static function getArticles() : array
{
$gwArticle = new DAL\ArticleGateway(new DAL\Connection('mysql:host = localhost; dbname = dbrorossetto', 'rorossetto', 'tpphp'));
$res = $gwArticle->getAllArticles();
foreach($res as $row){
$tabArticle[] = new metier\Article($row['id'], $row['title'],$row['datePub'],$row['description'],$row['guid'],$row['link'],$row['mediaContent'],$row['provenance'] );
}
return $tabArticle;
}
}

@ -1,10 +1,17 @@
<?php <?php
namespace modeles; namespace model;
use DAL\FluxGateway;
use metier\Flux;
class FluxModel class FluxModel
{ {
private FluxGateway $gateway; private FluxGateway $gateway;
public function __construct(FluxGateway $fluxGateway){
$this->gateway = $fluxGateway;
}
public function FindAllFlux(){ public function FindAllFlux(){
$data = array(); $data = array();
$result = $this->gateway->findAllFlux(); $result = $this->gateway->findAllFlux();
@ -17,7 +24,7 @@ class FluxModel
public function addFlux(Flux $flux) public function addFlux(Flux $flux)
{ {
$data = findFlux($flux); $data = $this->findFlux($flux);
if ($data == array()) { if ($data == array()) {
$this->gateway->addFlux($flux); $this->gateway->addFlux($flux);
} }

@ -1,17 +1,17 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="fr"> <html lang="fr">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Erreur</title> <title>Erreur</title>
</head> </head>
<body> <body>
<h1>ERREUR page !!!!!</h1> <h1>ERREUR page !!!!!</h1>
{% if dVueEreur is defined %} {% if dVueEreur is defined %}
{% for value in dVueEreur %} {% for value in dVueEreur %}
<p>{{value}}</p> <p>{{value}}</p>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</body> </body>
</html> </html>

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>All Articles</title>
</head>
<body>
{% for value in tabArticle.Article %}
<p>{{value}}</p>
{% endfor %}
</body>
</html>

@ -1,105 +1,105 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="fr"> <html lang="fr">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Personne - formulaire</title> <title>Personne - formulaire</title>
<script type="text/javascript"> <script type="text/javascript">
function clearForm(oForm) { function clearForm(oForm) {
const elements = oForm.elements; const elements = oForm.elements;
oForm.reset(); oForm.reset();
for (i = 0; i < elements.length; i++) { for (i = 0; i < elements.length; i++) {
field_type = elements[i].type.toLowerCase(); field_type = elements[i].type.toLowerCase();
switch (field_type) { switch (field_type) {
case "text": case "text":
case "password": case "password":
case "textarea": case "textarea":
case "hidden": case "hidden":
elements[i].value = ""; elements[i].value = "";
break; break;
case "radio": case "radio":
case "checkbox": case "checkbox":
if (elements[i].checked) { if (elements[i].checked) {
elements[i].checked = false; elements[i].checked = false;
} }
break; break;
case "select-one": case "select-one":
case "select-multi": case "select-multi":
elements[i].selectedIndex = -1; elements[i].selectedIndex = -1;
break; break;
default: default:
break; break;
} }
} }
} }
</script> </script>
</head> </head>
<body> <body>
<!-- on vérifie les données provenant du modèle --> <!-- on vérifie les données provenant du modèle -->
{% if dVue is defined %} {% if dVue is defined %}
<div align="center"> <div align="center">
{% if dVueEreur is defined and dVueEreur|length >0 %} {% if dVueEreur is defined and dVueEreur|length >0 %}
<h2>ERREUR !!!!!</h2> <h2>ERREUR !!!!!</h2>
{% for value in dVueEreur %} {% for value in dVueEreur %}
<p>{{value}}</p> <p>{{value}}</p>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
<h2>Personne - formulaire</h2> <h2>Personne - formulaire</h2>
<hr /> <hr />
<!-- affichage de données provenant du modèle --> <!-- affichage de données provenant du modèle -->
{{dVue.data}} {{dVue.data}}
<form method="post" name="myform" id="myform"> <form method="post" name="myform" id="myform">
<table> <table>
<tr> <tr>
<td>Nom</td> <td>Nom</td>
<td> <td>
<input name="txtNom" value="{{dVue.nom}}" type="text" size="20" /> <input name="txtNom" value="{{dVue.nom}}" type="text" size="20" />
</td> </td>
</tr> </tr>
<tr> <tr>
<td>Age</td> <td>Age</td>
<td> <td>
<input <input
name="txtAge" name="txtAge"
value="{{dVue.age}}" value="{{dVue.age}}"
type="text" type="text"
size="3" size="3"
required required
/> />
</td> </td>
</tr> </tr>
<tr></tr> <tr></tr>
</table> </table>
<table> <table>
<tr> <tr>
<td><input type="submit" value="Envoyer" /></td> <td><input type="submit" value="Envoyer" /></td>
<td><input type="reset" value="Rétablir" /></td> <td><input type="reset" value="Rétablir" /></td>
<td> <td>
<input <input
type="button" type="button"
value="Effacer" value="Effacer"
onclick="clearForm(this.form);" onclick="clearForm(this.form);"
/> />
</td> </td>
</tr> </tr>
</table> </table>
<!-- action !!!!!!!!!! --> <!-- action !!!!!!!!!! -->
<input type="hidden" name="action" value="validationFormulaire" /> <input type="hidden" name="action" value="validationFormulaire" />
</form> </form>
</div> </div>
{% else %} {% else %}
<p>Erreur !!<br />utilisation anormale de la vuephp</p> <p>Erreur !!<br />utilisation anormale de la vuephp</p>
{% endif %} {% endif %}
<p> <p>
Essayez de mettre du code html dans nom -> Correspond à une attaque de type injection Essayez de mettre du code html dans nom -> Correspond à une attaque de type injection
</p> </p>
</body> </body>
</html> </html>

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save