MODIFY : restructuration des fichiers Modele et ajout des erreurs de création de tache ou de liste

master
Lucie Bedouret 2 years ago
parent ba0806aab2
commit 5a685d0399

@ -62,7 +62,7 @@
} }
static function clear_string($champ){ static function clear_string($champ){
return filter_var($champ, FILTER_SANITIZE_SPECIAL_CHARS); return filter_var($champ, FILTER_SANITIZE_STRING);
} }
} }

@ -8,22 +8,12 @@ $bd['user'] = "root";
$bd['pswd'] = "root"; $bd['pswd'] = "root";
//Vues //Vues
$vues['acceuil']='vues/acceuil.php'; $vues['acceuil']='vues/acceuil.php';
$vues['erreur']='vues/erreur.php';
$vues['connection']='vues/connection.php'; $vues['connection']='vues/connection.php';
$vues['inscription']='vues/inscription.php'; $vues['inscription']='vues/inscription.php';
$vues['profile']='vues/profile.php';
$vues['listesPrivees']='vues/listesPrivees.php'; $vues['listesPrivees']='vues/listesPrivees.php';
$vues['creationListe']='vues/creationListe.php'; $vues['creationListe']='vues/creationListe.php';
$vues['infosListe']='vues/infosListe.php'; $vues['infosListe']='vues/infosListe.php';
$vues['creationTache']='vues/creationTache.php'; $vues['creationTache']='vues/creationTache.php';
// Styles
$styles['commun']='styles/commonStyles.css';
$styles['acceuil']='styles/acceuilStyles.css';
$styles['connection']='styles/connectionStyles.css';
$styles['listesPv']="styles/privateListsStyles.css";
// Assets
$assets['logo']='assets/logo.png';
?> ?>

@ -20,8 +20,6 @@ class ControleurUtilisateur{
} }
} }
function creerListePv($arrayErrorViews){ function creerListePv($arrayErrorViews){
global $rep, $vues, $dataView; global $rep, $vues, $dataView;
//recupérer les valeurs du formulaire //recupérer les valeurs du formulaire
@ -35,14 +33,14 @@ class ControleurUtilisateur{
// appelle à la methode du modèle // appelle à la methode du modèle
if($privee == true){ if($privee == true){
try{ try{
UserModel::creerListePv($nomListe,$_SESSION['login']); ListeModel::creerListePv($nomListe,$_SESSION['login']);
} catch (PDOException $e){ } catch (PDOException $e){
$dataView[]="Erreur inatendue"; $dataView[]="Erreur inatendue";
require($rep.$vues['erreur']); require($rep.$vues['erreur']);
} }
}else{ }else{
try{ try{
VisitorModel::creerListe($nomListe); ListeModel::creerListe($nomListe);
} catch (PDOException $e){ } catch (PDOException $e){
$dataView[]="Erreur inatendue"; $dataView[]="Erreur inatendue";
require($rep.$vues['erreur']); require($rep.$vues['erreur']);
@ -52,7 +50,7 @@ class ControleurUtilisateur{
function accessPrivateLists($arrayErrorViews){ function accessPrivateLists($arrayErrorViews){
global $rep, $vues, $dataView; global $rep, $vues, $dataView;
$model = new UserModel(); $model = new ListeModel();
$dataView = $model->pullListesPrivees($_SESSION['login']); $dataView = $model->pullListesPrivees($_SESSION['login']);
require($rep.$vues['listesPrivees']); require($rep.$vues['listesPrivees']);
} }

@ -75,7 +75,7 @@ class ControleurVisiteur {
public function reinit(){ public function reinit(){
global $rep,$vues,$dataView,$styles; global $rep,$vues,$dataView,$styles;
$model = new VisiteurModel(); $model = new ListeModel();
$dataView = $model->pullPublicLists(); $dataView = $model->pullPublicLists();
require($rep.$vues['acceuil']); require($rep.$vues['acceuil']);
@ -93,7 +93,7 @@ class ControleurVisiteur {
global $rep,$vues,$dataView; global $rep,$vues,$dataView;
$nom=$_POST['name']; $nom=$_POST['name'];
$idListe=$_POST['liste']; $idListe=$_POST['liste'];
$model = new ListeModel(); $model = new TacheModel();
$model->addTache($nom,$idListe); $model->addTache($nom,$idListe);
$_REQUEST['action']="accessListInfos"; $_REQUEST['action']="accessListInfos";
$this->accessListInfos($arrayErrorViews); $this->accessListInfos($arrayErrorViews);
@ -102,7 +102,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'];
$model= new ListeModel(); $model= new TacheModel();
$model->delTache($idTache); $model->delTache($idTache);
$_REQUEST['action']="accessListInfos"; $_REQUEST['action']="accessListInfos";
$this->accessListInfos($arrayErrorViews); $this->accessListInfos($arrayErrorViews);
@ -111,7 +111,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'];
$model = new ListeModel(); $model = new TacheModel();
$model->changeCompletedTache($idTache); $model->changeCompletedTache($idTache);
$_REQUEST['action']="accessListInfos"; $_REQUEST['action']="accessListInfos";
$this->accessListInfos($arrayErrorViews); $this->accessListInfos($arrayErrorViews);
@ -125,7 +125,7 @@ class ControleurVisiteur {
if(!empty($vues_erreur)){ if(!empty($vues_erreur)){
require($rep.$vues['connection']); require($rep.$vues['connection']);
} }
$model= new VisiteurModel(); $model= new UserModel();
if($model->existUser($usrname)){ if($model->existUser($usrname)){
if(password_verify($pwd,$model->getHashedPassword($usrname))){ if(password_verify($pwd,$model->getHashedPassword($usrname))){
$model->connexion($usrname); $model->connexion($usrname);
@ -148,7 +148,7 @@ class ControleurVisiteur {
$usrname=$_POST['username']; $usrname=$_POST['username'];
$pwd=$_POST['password']; $pwd=$_POST['password'];
$confirm=$_POST['confirmpassword']; $confirm=$_POST['confirmpassword'];
$model = new VisiteurModel(); $model = new UserModel();
$vues_erreur=Validation::val_inscription($usrname,$pwd,$confirm,$vues_erreur); $vues_erreur=Validation::val_inscription($usrname,$pwd,$confirm,$vues_erreur);
if($model->existUser($usrname)){ if($model->existUser($usrname)){
$vues_erreur[]="Username already taken"; $vues_erreur[]="Username already taken";
@ -162,7 +162,7 @@ class ControleurVisiteur {
} }
$_REQUEST['action']=null; $_REQUEST['action']=null;
new ControleurVisiteur(); $this->reinit();
} }
public function creerListe(array $vues_erreur){ public function creerListe(array $vues_erreur){
@ -189,17 +189,6 @@ class ControleurVisiteur {
$_REQUEST['action']=null; $_REQUEST['action']=null;
$this->reinit(); $this->reinit();
} }
public function creerTache(array $vues_erreur){
global $rep, $vues;
require($rep.$vues['creerTache']);
$intitule = $_POST['intitule'];
$vues_erreur=Validation::val_intitule($intitule, $vues_erreur);
$model = new ListeModel();
$model->creerTache();
}
} }
?> ?>

@ -44,71 +44,6 @@ class UserGateway {
return true; return true;
} }
function delUtilisateur(int $id){
if(!empty($id)){
try{
$co = $this->co;
$query = "DELETE FROM Utilisateur WHERE id=:id";
$co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR)));
}
catch(PDOException $Exception){
echo 'erreur';
echo $Exception->getMessage();
}
}
}
function putUtilisateur(Utilisateur $usr){
if(!empty($usr.getId()) && !empty($usr.getNom()) && empty($usr.getPassword())){
try{
$co = $this->co;
$updateQuery = "UPDATE Utilisateur SET id=:id AND nom=:nom AND pwd=:pwd";
$deleteQuery = "DELETE FROM HasList WHERE user=:id AND liste=:liste";
$insertQuery = "INSERT INTO HasList VALUES (:id, :liste)";
$co->executeQuery($updateQuery, array(':id' => array($usr.getId(), PDO::PARAM_STR), ':nom' => array($usr.getNom(), PDO::PARAM_STR), ':pwd' => array($usr.getPassword(), PDO::PARAM_STR)));
foreach($usr.getListListe() as $l){
$co->executeQuery($deleteQuery, array(':id' => array($usr.getId(), PDO::PARAM_STR), ':liste' => array($l, PDO::PARAM_STR)));
$co->executeQuery($insertQuery, array(':id' => array($usr.getId(), PDO::PARAM_STR), ':liste' => array($l, PDO::PARAM_STR)));
}
}
catch(PDOException $Excception){
echo 'erreur';
echo $Excception->getMesage();
}
}
}
function getUtilisateurById(int $id) : Utilisateur {
$usr = null;
if(!empty($id)){
try{
$co = $this->co;
$query = "SELECT * FROM Utilisateur WHERE id=:id";
$co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR)));
$results = $co->getResults();
foreach($results as $row){
$usr = new Utilisateur($row['id'], $row['nom'], $row['pwd']);
}
}
catch(PDOException $Exception){
echo 'erreur';
echo $Exception->getMessage();
}
}
return $usr;
}
function getUtilisateurbyName(string $nom) : ?Utilisateur { function getUtilisateurbyName(string $nom) : ?Utilisateur {
$usr = null; $usr = null;
$tabList= null; $tabList= null;

@ -1,7 +1,7 @@
<?php <?php
class ListeModel{ class ListeModel{
public $listgw; private $listgw;
function __construct(){ function __construct(){
global $rep,$vues,$bd; global $rep,$vues,$bd;
@ -9,37 +9,41 @@ class ListeModel{
$this->listgw = new ListeGateway($co); $this->listgw = new ListeGateway($co);
} }
public function get_gtwListe(){
return $this->listgw;
}
function creerListe(string $nom, $private){ function creerListe(string $nom, $private){
if(isset($_SESSION['login'])){ if(isset($_SESSION['login'])){
if($private!=null){ if($private!=null){
$this->listgw->creerListe($nom,$_SESSION['login']); $this->get_gtwListe()->creerListe($nom,$_SESSION['login']);
}else{ }else{
$this->listgw->creerListe($nom,null); $this->get_gtwListe()->creerListe($nom,null);
} }
}else{ }else{
$this->listgw->creerListe($nom,null); $this->get_gtwListe()->creerListe($nom,null);
} }
} }
function pullListById(int $idListe){ function creerListePv($nom,$idCeator){
return $this->listgw->getById($idListe); $this->get_gtwListe()->creerListe($nom,$idCreator);
} }
function addTache(string $intitule, int $idListe ){ public function pullPublicLists(){
$this->listgw->creerTache($intitule,$idListe); return $this->get_gtwListe()->getPublicLists();
} }
function delTache(int $idTache){ function pullListesPrivees($nom){
$this->listgw->delTache($idTache); $listes=$this->get_gtwListe()->getByCreator($nom);
return $listes;
} }
function changeCompletedTache(int $idTache){ function pullListById(int $idListe){
$complete=$this->listgw->getTacheById($idTache); return $this->get_gtwListe()->getById($idListe);
$this->listgw->updateTache($idTache,$complete);
} }
function delListe(int $idListe){ function delListe(int $idListe){
$this->listgw->delListe($idListe); $this->get_gtwListe()->delListe($idListe);
} }
} }

@ -0,0 +1,32 @@
<?php
class TacheModel {
private $gwList;
public function __construct() {
global $rep,$vues,$bd;
$co = new Connection($bd['dsn'],$bd['user'],$bd['pswd']);
$this->gwList = new ListeGateway($co);
}
public function get_gwList(){
return $this->gwList;
}
function addTache(string $intitule, int $idListe ){
$this->get_gwList()->creerTache($intitule,$idListe);
}
function delTache(int $idTache){
$this->get_gwList()->delTache($idTache);
}
function changeCompletedTache(int $idTache){
$complete=$this->get_gwList()->getTacheById($idTache);
$this->get_gwList()->updateTache($idTache,$complete);
}
}
?>

@ -1,14 +1,16 @@
<?php <?php
class UserModel{ class UserModel{
public $listgw; private $usergw;
public $usergw;
function __construct(){ function __construct(){
global $rep,$vues,$bd; global $rep,$vues,$bd;
$co = new Connection($bd['dsn'],$bd['user'],$bd['pswd']); $co = new Connection($bd['dsn'],$bd['user'],$bd['pswd']);
$this->usergw = new UserGateway($co); $this->usergw = new UserGateway($co);
$this->listgw = new ListeGateway($co); }
public function get_UserGw(){
return $this->usergw;
} }
function deconnection(){ function deconnection(){
@ -17,22 +19,32 @@ class UserModel{
$_SESSION = array(); $_SESSION = array();
} }
function creerListePv($nom,$idCeator){ public function getHashedPassword(string $usr){
$this->listgw->creerListe($nom,$idCreator); return $this->get_UserGw()->getHashedPassword($usr);
} }
function desinscription($login){ public function existUser(string $usr):bool{
$this->usergw->delUtilisateur($login); if($this->get_UserGw()->getUtilisateurNom($usr) != null){
return true;
}
return false;
} }
function changerPassword($newPassword){ public function connexion($login){
$this->usergw->putPassword($newPassword); $_SESSION['role'] = 'Utilisateur';
$_SESSION['login'] = $login;
} }
function pullListesPrivees($nom){
$listes=$this->listgw->getByCreator($nom); public function inscription($login, $mdp){
return $listes; $result=$this->get_UserGw()->creerUtilisateur($login, $mdp);
if ($result ==true){
$_SESSION['role'] = 'Utilisateur';
$_SESSION['login'] = $login;
}
} }
} }
?> ?>

@ -1,51 +0,0 @@
<?php
class VisiteurModel {
public $gtwUsr;
public $gtwListe;
public function __construct() {
global $rep,$vues,$bd;
$co = new Connection($bd['dsn'],$bd['user'],$bd['pswd']);
$this->gtwUsr = new UserGateway($co);
$this->gtwListe = new ListeGateway($co);
}
public function getHashedPassword(string $usr){
return $this->gtwUsr->getHashedPassword($usr);
}
public function existUser(string $usr):bool{
if($this->gtwUsr->getUtilisateurNom($usr) != null){
return true;
}
return false;
}
public function connexion($login){
$_SESSION['role'] = 'Utilisateur';
$_SESSION['login'] = $login;
}
public function pullPublicLists(){
return $this->gtwListe->getPublicLists();
}
public function inscription($login, $mdp){
$result=$this->gtwUsr->creerUtilisateur($login, $mdp);
if ($result ==true){
$_SESSION['role'] = 'Utilisateur';
$_SESSION['login'] = $login;
}
}
public function supprListe($id) {
$this->get_gtwListe()->delListe($id);
}
public function creerTache(string $intitule){
$this->get_gtwListe()->creerTache($intitule);
}
}
?>

@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<title>creationListe</title> <title>creationListe</title>
<link rel="stylesheet" href="<?=$styles['commun']?>"/> <link rel="stylesheet" href="styles/commonStyles.css"/>
<link rel="stylesheet" href="styles/creationStyles.css"/> <link rel="stylesheet" href="styles/creationStyles.css"/>
</head> </head>
<body> <body>
@ -26,6 +26,12 @@
'; ';
} }
?> ?>
<br/>
<?php
if(isset($vues_erreur)){
echo '<h4 id="error">'.$vues_erreur[0].'</h4>';
}
?>
<input class="button" type="submit" value="Create List"/> <input class="button" type="submit" value="Create List"/>
<input type="hidden" name="action" value="creerListe"/> <input type="hidden" name="action" value="creerListe"/>
</form> </form>

@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<title>creationTache</title> <title>creationTache</title>
<link rel="stylesheet" href="<?=$styles['commun']?>"> <link rel="stylesheet" href="styles/commonStyles.css">
<link rel="stylesheet" href="styles/creationStyles.css"> <link rel="stylesheet" href="styles/creationStyles.css">
</head> </head>
<body> <body>
@ -17,6 +17,14 @@
<form method="post" name="creationForm" id="creationForm"> <form method="post" name="creationForm" id="creationForm">
<h4>Name of the task</h4> <h4>Name of the task</h4>
<input type="text" name="name" id="name" required/> <input type="text" name="name" id="name" required/>
<br/>
<?php
if(isset($vues_erreur)){
echo '<h4 id="error">'.$vues_erreur[0].'</h4>';
}
?>
<input class="button" type="submit" value="Create"/> <input class="button" type="submit" value="Create"/>
<input type="hidden" name="action" value="addTache"/> <input type="hidden" name="action" value="addTache"/>
<input type="hidden" name="liste" value="<?=$dataView?>"/> <input type="hidden" name="liste" value="<?=$dataView?>"/>

@ -1,17 +0,0 @@
<!DOCTYPE html>
<html>
<body>
<div>
<h3>Error!</h3>
<?php
if (isset($dataVueErreur)) {
foreach ($dataVueErreur as $value){
echo $value;
}
}
?>
</div>
</body>
</html>
Loading…
Cancel
Save