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

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

@ -1,7 +1,7 @@
<?php
class ListeModel{
public $listgw;
private $listgw;
function __construct(){
global $rep,$vues,$bd;
@ -9,37 +9,41 @@ class ListeModel{
$this->listgw = new ListeGateway($co);
}
public function get_gtwListe(){
return $this->listgw;
}
function creerListe(string $nom, $private){
if(isset($_SESSION['login'])){
if($private!=null){
$this->listgw->creerListe($nom,$_SESSION['login']);
$this->get_gtwListe()->creerListe($nom,$_SESSION['login']);
}else{
$this->listgw->creerListe($nom,null);
$this->get_gtwListe()->creerListe($nom,null);
}
}else{
$this->listgw->creerListe($nom,null);
$this->get_gtwListe()->creerListe($nom,null);
}
}
function pullListById(int $idListe){
return $this->listgw->getById($idListe);
function creerListePv($nom,$idCeator){
$this->get_gtwListe()->creerListe($nom,$idCreator);
}
function addTache(string $intitule, int $idListe ){
$this->listgw->creerTache($intitule,$idListe);
public function pullPublicLists(){
return $this->get_gtwListe()->getPublicLists();
}
function delTache(int $idTache){
$this->listgw->delTache($idTache);
function pullListesPrivees($nom){
$listes=$this->get_gtwListe()->getByCreator($nom);
return $listes;
}
function changeCompletedTache(int $idTache){
$complete=$this->listgw->getTacheById($idTache);
$this->listgw->updateTache($idTache,$complete);
function pullListById(int $idListe){
return $this->get_gtwListe()->getById($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
class UserModel{
public $listgw;
public $usergw;
private $usergw;
function __construct(){
global $rep,$vues,$bd;
$co = new Connection($bd['dsn'],$bd['user'],$bd['pswd']);
$this->usergw = new UserGateway($co);
$this->listgw = new ListeGateway($co);
}
public function get_UserGw(){
return $this->usergw;
}
function deconnection(){
@ -17,22 +19,32 @@ class UserModel{
$_SESSION = array();
}
function creerListePv($nom,$idCeator){
$this->listgw->creerListe($nom,$idCreator);
public function getHashedPassword(string $usr){
return $this->get_UserGw()->getHashedPassword($usr);
}
function desinscription($login){
$this->usergw->delUtilisateur($login);
public function existUser(string $usr):bool{
if($this->get_UserGw()->getUtilisateurNom($usr) != null){
return true;
}
return false;
}
function changerPassword($newPassword){
$this->usergw->putPassword($newPassword);
public function connexion($login){
$_SESSION['role'] = 'Utilisateur';
$_SESSION['login'] = $login;
}
function pullListesPrivees($nom){
$listes=$this->listgw->getByCreator($nom);
return $listes;
public function inscription($login, $mdp){
$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>
<head>
<title>creationListe</title>
<link rel="stylesheet" href="<?=$styles['commun']?>"/>
<link rel="stylesheet" href="styles/commonStyles.css"/>
<link rel="stylesheet" href="styles/creationStyles.css"/>
</head>
<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 type="hidden" name="action" value="creerListe"/>
</form>

@ -2,7 +2,7 @@
<html>
<head>
<title>creationTache</title>
<link rel="stylesheet" href="<?=$styles['commun']?>">
<link rel="stylesheet" href="styles/commonStyles.css">
<link rel="stylesheet" href="styles/creationStyles.css">
</head>
<body>
@ -17,6 +17,14 @@
<form method="post" name="creationForm" id="creationForm">
<h4>Name of the task</h4>
<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 type="hidden" name="action" value="addTache"/>
<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