Compare commits

...

3 Commits

@ -58,19 +58,8 @@
return $dataVueEreur;
}
static function val_id($id, $dataVueEreur){
if (!isset($id)||$id=""){
$dataVueEreur[] = "Id error";
}
if($id != filter_var($id, FILTER_VALIDATE_INT)){
$dataVueEreur[] = "Id validation error";
$id = 0;
}
return $dataVueEreur;
}
static function clear_string($champ){
return filter_var($champ, FILTER_SANITIZE_SPECIAL_CHARS);
return filter_var($champ, FILTER_SANITIZE_STRING);
}
}

@ -3,27 +3,17 @@
//Prefixe
$rep=__DIR__.'/../';
//BD
$bd['dsn'] = "mysql:host=localhost;port=8888;dbname=bdPhp";
$bd['dsn'] = "mysql:host=localhost;port=8888;dbname=dbPhp";
$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']);
}

@ -4,7 +4,7 @@ class ControleurVisiteur {
public function __construct() {
global $rep,$vues,$dataView,$styles,$assets;
$arrayErrorViews= array();
$vues_erreur= array();
try{
$action = $_REQUEST['action']??null;
switch($action){
@ -28,33 +28,33 @@ class ControleurVisiteur {
require($rep.$vues['creationTache']);
break;
case "addTache":
$this->addTache($arrayErrorViews);
$this->addTache($vues_erreur);
break;
case "accessListInfos":
$this->accessListInfos($arrayErrorViews);
$this->accessListInfos($vues_erreur);
break;
case "delTache":
$this->delTache($arrayErrorViews);
$this->delTache($vues_erreur);
break;
case "changeCompletedTache":
$this->changeCompletedTache($arrayErrorViews);
$this->changeCompletedTache($vues_erreur);
break;
case "connection":
$this->connection($arrayErrorViews);
$this->connection($vues_erreur);
break;
case "inscription":
$this->inscription($arrayErrorViews);
$this->inscription($vues_erreur);
case "creerListe":
$this->creerListe($arrayErrorViews);
$this->creerListe($vues_erreur);
break;
case "delListe":
$this->delListe($arrayErrorViews);
$this->delListe($vues_erreur);
break;
case "deconnection":
$this->deconnection($arrayErrorViews);
$this->deconnection($vues_erreur);
break;
default :
$arrayErrorViews[]="Erreur innatendue !!!";
$vues_erreur[]="Erreur innatendue !!!";
require($rep.$vues['acceuil']);
}
} catch(PDOException $e){
@ -65,61 +65,68 @@ class ControleurVisiteur {
}
function deconnection($arrayErrorViews){
function deconnection($vues_erreur){
global $rep, $vues, $dataView;
$model = new UserModel();
$retour = $model->deconnection();
$_REQUEST['action']=null;
$control= new ControleurVisiteur();
$vues_erreur= array();
}
public function reinit(){
global $rep,$vues,$dataView,$styles;
$model = new VisiteurModel();
$model = new ListeModel();
$dataView = $model->pullPublicLists();
require($rep.$vues['acceuil']);
$vues_erreur= array();
}
public function accessListInfos($arrayErrorViews){
public function accessListInfos($vues_erreur){
global $rep,$vues,$dataView;
$idListe=$_POST['liste'];
$arrayErrorViews = Validation::val_id($idListe, $arrayErrorViews);
$model = new ListeModel();
$dataView = $model->pullListById($idListe);
require($rep.$vues['infosListe']);
$vues_erreur= array();
}
public function addTache($arrayErrorViews){
public function addTache($vues_erreur){
global $rep,$vues,$dataView;
$nom=$_POST['name'];
$idListe=$_POST['liste'];
$arrayErrorViews = Validation::val_intitule($name, $arrayErrorViews);
$arrayErrorViews = Validation::val_id($idListe, $arrayErrorViews);
$model = new ListeModel();
$model->addTache($nom,$idListe);
$_REQUEST['action']="accessListInfos";
$this->accessListInfos($arrayErrorViews);
$vues_erreur = Validation::val_intitule($nom, $vues_erreur);
if(!empty($vues_erreur)){
require($rep.$vues['creationTache']);
}
else{
$model = new TacheModel();
$model->addTache($nom,$idListe);
$_REQUEST['action']="accessListInfos";
$this->accessListInfos($vues_erreur);
$vues_erreur= array();
}
}
public function delTache($arrayErrorViews){
public function delTache($vues_erreur){
global $rep,$vues,$dataView;
$idTache=$_POST['tache'];
$arrayErrorViews = Validation::val_id($idTache, $arrayErrorViews);
$model= new ListeModel();
$model= new TacheModel();
$model->delTache($idTache);
$_REQUEST['action']="accessListInfos";
$this->accessListInfos($arrayErrorViews);
$this->accessListInfos($vues_erreur);
$vues_erreur= array();
}
public function changeCompletedTache($arrayErrorViews){
public function changeCompletedTache($vues_erreur){
global $rep,$vues,$dataView;
$idTache=$_POST['tache'];
$arrayErrorViews = Validation::val_id($idTache, $arrayErrorViews);
$model = new ListeModel();
$model = new TacheModel();
$model->changeCompletedTache($idTache);
$_REQUEST['action']="accessListInfos";
$this->accessListInfos($arrayErrorViews);
$this->accessListInfos($vues_erreur);
$vues_erreur= array();
}
public function connection(array $vues_erreur){
@ -130,12 +137,13 @@ 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);
$_REQUEST['action']=null;
$this->reinit();
$vues_erreur= array();
}
else{
$vues_erreur =array('username'=>$usrname,'password'=>$pwd);
@ -153,7 +161,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";
@ -161,50 +169,47 @@ class ControleurVisiteur {
if(empty($vues_erreur)){
$hash= password_hash($pwd,PASSWORD_DEFAULT);
$model->inscription($usrname,$hash);
$vues_erreur= array();
}
else{
require($rep.$vues['inscription']);
}
$_REQUEST['action']=null;
new ControleurVisiteur();
$this->reinit();
}
public function creerListe(array $vues_erreur){
global $rep, $vues;
$nom=$_POST['name'];
$vues_erreur=Validation::val_intitule($nom, $vues_erreur);
$model = new ListeModel();
if(isset($_SESSION['login'])){
$private=$_POST['private'];
$model->creerListe($nom,$private);
if(!empty($vues_erreur)){
require($rep.$vues['creationListe']);
}
else{
$model->creerListe($nom,null);
$model = new ListeModel();
if(isset($_SESSION['login'])){
$private=$_POST['private'];
$model->creerListe($nom,$private);
}
else{
$model->creerListe($nom,null);
}
$_REQUEST['action']=null;
$this->reinit();
$vues_erreur= array();
}
$_REQUEST['action']=null;
$this->reinit();
}
public function delListe(array $vues_erreur){
global $rep, $vues;
$idListe=$_POST['liste'];
$arrayErrorViews = Validation::val_id($idListe, $arrayErrorViews);
$model = new ListeModel();
$model->delListe($idListe);
$_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();
$vues_erreur= array();
}
}

@ -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);
}
}
?>

@ -20,7 +20,7 @@
<h4>Password</h4>
<input type="password" name="mdp" required/>
<?php
if(isset($vues_erreur)){
if(!empty($vues_erreur)){
echo '<h4 id="error">Incorrect Username or Password</h4>';
}
?>

@ -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(!empty($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(!empty($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>

@ -61,6 +61,7 @@
<input type="hidden" name="action" value="accessCreationTachePage"/>
<input type="hidden" name="liste" value="<?=$dataView->get_id()?>"/>
</form>
<form method="POST" id="delListe" name="delListe">
<input class="del-list" type="submit" value="Delete the list"/></p>
<input type="hidden" name="action" value="delListe"/>

@ -23,7 +23,7 @@
<h4>Confirm Password</h4>
<input type="password" name="confirmpassword" required/>
<?php
if(isset($vues_erreur)){
if(!empty($vues_erreur)){
echo '<h4 id="error">'.$vues_erreur[0].'</h4>';
}
?>

Loading…
Cancel
Save