visitor-controller
Anna BOUDOUL 2 years ago
commit 6b1c67a410

@ -0,0 +1,33 @@
<?php
class Validation {
static function val_form_texte(&$texte, &$TMessage) {
if (!isset($texte)||$texte=="") {
$TMessage[] ="Empty fields";
$texte="";
}
if ($texte != filter_var($texte, FILTER_SANITIZE_STRING))
{
$TMessage[]="Attempt to inject code (security attack)";
$texte="";
}
}
static function val_form_mdp(&$mdp, &$TMessage) {
if (!isset($mdp)||$mdp=="") {
$TMessage[] ="Password not specified";
$mdp="";
}
if ($mdp != filter_var($mdp, FILTER_SANITIZE_SPECIAL_CHARS))
{
$TMessage[] ="Password must not contain special characters";
$mdp="";
}
}
}
?>

@ -3,8 +3,8 @@
$rep=__DIR__.'/../';
$con = new Connection('mysql:host=localhost;dbname=phpproject', 'nifranco', 'achanger');
//$con = new Connection('mysql:host=localhost;dbname=dbanboudoul', 'anboudoul', 'mdpMYSQL');
//$con = new Connection('mysql:host=localhost;dbname=phpproject', 'nifranco', 'achanger');
$con = new Connection('mysql:host=localhost;dbname=dbanboudoul', 'anboudoul', 'mdpMYSQL');
$TMessage = array();
?>

@ -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

@ -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(){

@ -71,7 +71,7 @@ class VisitorCtrl
default:
#
$dvueErreur[] = 'Erreur inattendue';
$TMessage[] = 'Unexpected error';
require($rep.$vues['']);
break;
}

@ -1,8 +1,9 @@
<?php
require_once("config/config.php");
require_once("controller/FrontCtrl.php");
require('config/Validation.php');
require("view/erreur.php");
$fc = new FrontCtrl($con);
?>

@ -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() ??

@ -1,6 +1,8 @@
<?php
require('business/User.php');
require('dal/UserGateway.php');
require_once("config/config.php");
class UserModel{
private $con;
private $gat;
@ -11,12 +13,14 @@
}
function connexion($login, $mdp){
Validation::val_form_texte($login, $TMessage);
Validation::val_form_mdp($mdp, $TMessage);
$result = $this->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 +29,8 @@
$_SESSION = array();
}
function isConnected(){ //teste rôle dans la session, retourne instance dobjet ou booleen
function isConnected(){ //teste rôle dans la session, retourne instance dobjet ou booleen
Validation::val_form_texte($_SESSION['login'], $TMessage);
if(isset($_SESSION['login'])){
return true;
} else {
@ -34,20 +39,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 +71,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);

Loading…
Cancel
Save