diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..fd00510 Binary files /dev/null and b/.DS_Store differ diff --git a/assets/.DS_Store b/assets/.DS_Store new file mode 100644 index 0000000..e30f76e Binary files /dev/null and b/assets/.DS_Store differ diff --git a/assets/checklist.png b/assets/checklist.png new file mode 100644 index 0000000..5106553 Binary files /dev/null and b/assets/checklist.png differ diff --git a/config/Autoload.php b/config/Autoload.php index d651342..87afab1 100644 --- a/config/Autoload.php +++ b/config/Autoload.php @@ -1,5 +1,9 @@ \ No newline at end of file diff --git a/controleurs/ControleurUtilisateur.php b/controleurs/ControleurUtilisateur.php index 84260f2..1483345 100644 --- a/controleurs/ControleurUtilisateur.php +++ b/controleurs/ControleurUtilisateur.php @@ -1,15 +1,18 @@ accessPrivateLists($arrayErrorViews); + case "accessProfilePage": + require($rep.$vues['profile']); + break; case "deconnection": $this->deconnection($arrayErrorViews); break; @@ -28,14 +31,16 @@ class UserController{ } } - public function deconnection($arrayErrorViews){ - // appeler la méthode deco du modèle - $retour = UserModel::deconnection(); - require($rep.$vues['acceuil']); + function deconnection($arrayErrorViews){ + global $rep, $vues, $dataView; + $model = new UserModel(); + $retour = $model->deconnection(); + $_REQUEST['action']=null; + $control= new ControleurVisiteur(); } - public function creerListePv($arrayErrorViews){ - global $rep, $vues; + function creerListePv($arrayErrorViews){ + global $rep, $vues, $dataView; //recupérer les valeurs du formulaire $nomListe=$_POST['ListName']; $privee=$_POST['isPrivate']; @@ -62,20 +67,27 @@ class UserController{ } } - public function changerPassword($arrayErrorViews){ - global $rep, $vues; + function changerPassword($arrayErrorViews){ + global $rep, $vues, $dataView; $password1=$_POST['password1']; $passwordConfirm=$_POST['passwordConfirm']; $newPassword=Validation::val_changer_password($password1,$passwordConfirm); try{ UserModel::changerPassword($newPassword); - require($rep.$vues['profil']) + require($rep.$vues['profil']); }catch(PDOException $e){ $dataView[]="Erreur inatendue"; require($rep.$vues['erreur']); } } + + function accessPrivateLists($arrayErrorViews){ + global $rep, $vues, $dataView; + $model = new UserModel(); + $dataView = $model->pullListesPrivees($_SESSION['login']); + require($rep.$vues['listesPrivees']); + } } ?> \ No newline at end of file diff --git a/controleurs/ControleurVisiteur.php b/controleurs/ControleurVisiteur.php index dc2c06b..c07f498 100644 --- a/controleurs/ControleurVisiteur.php +++ b/controleurs/ControleurVisiteur.php @@ -1,19 +1,25 @@ reinit(); break; + case 'accessConnectionPage': + require($rep.$vues['connection']); + break; + case "accessInscription": + require($rep.$vues['inscription']); + break; + case "accessCreationListePage": + require($rep.$vues['creationListe']); + break; case "connection": $this->connection($arrayErrorViews); break; @@ -35,7 +41,7 @@ class VisitorController { $this->supprTache($arrayErrorViews); default : $arrayErrorViews[]="Erreur innatendue !!!"; - require($rep.$vues['error']); + require($rep.$vues['acceuil']); } } catch(PDOException $e){ $dataView[]="Erreur inatendue"; @@ -45,49 +51,67 @@ class VisitorController { } public function reinit(){ - global $rep,$vues; + global $rep,$vues,$dataView; + $model = new VisiteurModel(); + $dataView = $model->pullPublicLists(); require($rep.$vues['acceuil']); + } public function connection(array $vues_erreur){ - global $rep,$vues; - + global $rep,$vues,$dataView; $usrname=$_POST['login']; $pwd=$_POST['mdp']; Validation::clear_string($pwd); Validation::val_connexion($usrname,$pwd,$vues_erreur); - - $model = new UserModel(); - $worked=$model->connexion(); - /* Utiliser si jamais connexion n'a pas marché et qu'on veut remettre le login dans la page pour que le visiteur n'ait pas à le retaper - $dVue = array ( - 'username' => $usrname, - ); - */ - if($worked==false){ - require('erreur.php'); + $model= new VisiteurModel(); + if($model->existUser($usrname)){ + if(password_verify($pwd,$model->getHashedPassword($usrname))){ + $model->connexion($usrname); + $_REQUEST['action']=null; + $this->reinit(); + } + else{ + $arrayErrorViews =array('username'=>$usrname,'password'=>$pwd); + require($rep.$vues['erreur']); + } + } + else{ + $arrayErrorViews =array('username'=>$usrname,'password'=>$pwd); + require($rep.$vues['erreur']); } } public function inscription(array $vues_erreur){ - global $rep,$vues; - - $usrname=$_POST['login']; - $pwd=$_POST['mdp']; - Validation::val_connexion($usrname,$pwd,$vues_erreur); - - $model = new UserModel(); - $model->inscription(); + global $rep,$vues,$dataView; + $usrname=$_POST['username']; + $pwd=$_POST['password']; + $confirm=$_POST['confirmpassword']; + $vues_erreur=Validation::val_inscription($usrname,$pwd,$confirm,$vues_erreur); + if($vues_erreur == []){ + $hash= password_hash($pwd,PASSWORD_DEFAULT); + $model = new VisiteurModel(); + $model->inscription($usrname,$hash); + } + $_REQUEST['action']=null; + new ControleurVisiteur(); } public function creerListe(array $vues_erreur){ global $rep, $vues; - require($rep.$vues['creationListe']); - - $nom=$_POST['nom']; - + $nom=$_POST['name']; $model = new ListeModel(); - $model->creerListe($nom); + if(isset($_SESSION['login'])){ + foreach($_POST['private'] as $valeur){ + $private=$valeur; + $model->creerListe($nom,$private); + } + } + else{ + $model->creerListe($nom,null); + } + $_REQUEST['action']=null; + $this->reinit(); } public function supprListe(array $vues_erreur){ diff --git a/controleurs/FrontControleur.php b/controleurs/FrontControleur.php index 22e743c..f0e4af6 100644 --- a/controleurs/FrontControleur.php +++ b/controleurs/FrontControleur.php @@ -1,27 +1,24 @@ diff --git a/modeles/Connection.php b/modeles/Gateways/Connection.php similarity index 100% rename from modeles/Connection.php rename to modeles/Gateways/Connection.php diff --git a/modeles/Gateways/ListeGateway.php b/modeles/Gateways/ListeGateway.php index 5d48252..30c9c11 100644 --- a/modeles/Gateways/ListeGateway.php +++ b/modeles/Gateways/ListeGateway.php @@ -9,38 +9,81 @@ class ListeGateway { $this->co = $co; } - public function getByCreator(int $idUsr) : array { - $listes = null; + public function getPublicLists():array{ + $listes = array(); $taches = null; - if(!empty($idUsr)){ - try { - $co = $this->co; + try { + $co = $this->co; - $query = "SELECT idListe FROM HasList WHERE idUser=:idUser"; + $query = "SELECT * FROM Liste WHERE nomCreateur IS NULL"; - $co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR))); + $co->executeQuery($query, []); - $results = $co->getResults(); + $results = $co->getResults(); - Foreach($results as $row){ - $idListe = $row['idListe']; - $queryTaches = "SELECT t.* FROM Tache t, HasTache h WHERE t.id=h.idTache AND h.idListe=:idListe"; - $co->executeQuery($queryTaches, array(':idListe' => array($idListe, PDO::PARAM_STR))); - $resultsTaches = $co->getResults(); + foreach($results as $row){ + $idListe = $row['id']; + $queryTaches = "SELECT * FROM Tache WHERE idListe=:idListe"; + $co->executeQuery($queryTaches, array(':idListe' => array($idListe, PDO::PARAM_INT))); + $resultsTaches = $co->getResults(); - Foreach($resultsTaches as $rowTaches){ - $taches[] = new Tache($rowTaches['id'], $rowTaches['intitule'], $rowTaches['isCompleted'], $rowTaches['description']); + foreach($resultsTaches as $rowTaches){ + if($rowTaches['complete']=="0"){ + $taches[] = new Tache($rowTaches['id'], $rowTaches['nom'],false,$idListe); + }else{ + $taches[] = new Tache($rowTaches['id'], $rowTaches['nom'],true,$idListe); } - - $listes[] = new Liste($row['id'], $row['nom'], $taches); - $taches = null; + } + + $listes[] = new Liste($row['id'], $row['nom'],null, $taches); + $taches = null; } - catch(PDOException $Exception) { - echo 'erreur'; - echo $Exception->getMessage(); + } + catch(PDOException $Exception) { + echo 'erreur'; + echo $Exception->getMessage(); + } + + return $listes; + } + + public function getByCreator(string $usr) : array { + $listes = array(); + $taches = null; + try { + $co = $this->co; + + $query = "SELECT * FROM Liste WHERE nomCreateur=:nomCrea"; + + $co->executeQuery($query, array('nomCrea' => array($usr, PDO::PARAM_STR))); + + $results = $co->getResults(); + + foreach($results as $row){ + $idListe = $row['id']; + $queryTaches = "SELECT * FROM Tache WHERE idListe=:idListe"; + $co->executeQuery($queryTaches, array(':idListe' => array($idListe, PDO::PARAM_INT))); + $resultsTaches = $co->getResults(); + + foreach($resultsTaches as $rowTaches){ + if($rowTaches['complete']=="0"){ + $taches[] = new Tache($rowTaches['id'], $rowTaches['nom'],false,$idListe); + }else{ + $taches[] = new Tache($rowTaches['id'], $rowTaches['nom'],true,$idListe); + } + + } + + $listes[] = new Liste($row['id'], $row['nom'],$usr, $taches); + $taches = null; } } + catch(PDOException $Exception) { + echo 'erreur'; + echo $Exception->getMessage(); + } + return $listes; } @@ -92,15 +135,15 @@ class ListeGateway { } } - public function creerListe(string $nom, int $idCreator){ + public function creerListe(string $nom, ?string $nomCreator){ try{ $co = $this->co; - $insertQuery = "INSERT INTO Liste VALUES (NULL, :nom, :idCreator)"; + $insertQuery = "INSERT INTO Liste VALUES (NULL, :nom, :nomCreator)"; $co->executeQuery($insertQuery, array('nom' => array($nom, PDO::PARAM_STR), - 'idCreator' => array($idCreator, PDO::PARAM_INT))); + 'nomCreator' => array($nomCreator, PDO::PARAM_STR))); } catch(PDOException $Exception){ echo 'erreur'; diff --git a/modeles/Gateways/UserGateway.php b/modeles/Gateways/UserGateway.php index ad6a852..2c84c61 100644 --- a/modeles/Gateways/UserGateway.php +++ b/modeles/Gateways/UserGateway.php @@ -1,32 +1,50 @@ co = $co; } - public function creerUtilisateur(string $nom, string $pwd){ - if(!empty($id) && !empty($nom) && empty($password)){ - try{ - $co = $this->co; + function getUtilisateurNom(string $usr){ + $co=$this->co; + $query="SELECT nom FROM Utilisateur WHERE nom=:nom"; + $co->executeQuery($query,array('nom'=>array($usr,PDO::PARAM_STR))); + return $co->getResults(); - $query = "INSERT INTO Utilisateur VALUES (NULL, :nom, :pwd)"; + } - $co->executeQuery($query, array(':nom' => array($nom, PDO::PARAM_STR), ':pwd' => array($pwd, PDO::PARAM_STR))); - } - catch(PDOException $Excception){ - echo 'erreur'; - echo $Exception->getMessage(); - } + function getHashedPassword(string $usrname):?string{ + $hashedPwd=null; + $co=$this->co; + $query="SELECT pwd FROM Utilisateur WHERE nom=:nom"; + $co->executeQuery($query,array('nom'=>array($usrname,PDO::PARAM_STR))); + $res=$co->getResults(); + foreach($res as $row){ + $hashedPwd=$row['pwd']; } + return $hashedPwd; } - public function delUtilisateur(int $id){ + function creerUtilisateur(string $nom, string $pwd){ + try{ + $co = $this->co; + + $query = "INSERT INTO Utilisateur VALUES (:nom, :pwd)"; + + $co->executeQuery($query, array(':nom' => array($nom, PDO::PARAM_STR), ':pwd' => array($pwd, PDO::PARAM_STR))); + } + catch(PDOException $Exception){ + echo 'erreur'; + echo $Exception->getMessage(); + return false; + } + + return true; + } + + function delUtilisateur(int $id){ if(!empty($id)){ try{ $co = $this->co; @@ -42,7 +60,7 @@ class UserGateway { } } - public function putUtilisateur(Utilisateur $usr){ + function putUtilisateur(Utilisateur $usr){ if(!empty($usr.getId()) && !empty($usr.getNom()) && empty($usr.getPassword())){ try{ $co = $this->co; @@ -66,7 +84,7 @@ class UserGateway { } } - public function getUtilisateurById(int $id) : Utilisateur { + function getUtilisateurById(int $id) : Utilisateur { $usr = null; if(!empty($id)){ try{ @@ -78,7 +96,7 @@ class UserGateway { $results = $co->getResults(); - Foreach($results as $row){ + foreach($results as $row){ $usr = new Utilisateur($row['id'], $row['nom'], $row['pwd']); } } @@ -91,27 +109,32 @@ class UserGateway { return $usr; } - public function getUtilisateurbyNameAndPassword(string $nom, string $pwd) : Utilisateur { + function getUtilisateurbyName(string $nom) : ?Utilisateur { $usr = null; - if(!empty($nom) && !empty($password)){ - try{ - $co = $this->co; + $tabList= null; + try{ + $co = $this->co; - $query = "SELECT * FROM Utilisateur WHERE nom=:nom AND pwd=:pwd"; + $queryLists="SELECT id, nom FROM Liste WHERE nomCreateur=:nomCrea"; + $queryUser = "SELECT * FROM Utilisateur WHERE nom=:nom"; - $co->executeQuery($query, array(':nom' => array($nom, PDO::PARAM_STR), ':pwd' => array($pwd, PDO::PARAM_STR))); + $co->executeQuery($queryLists,array('nomCrea'=>array($nom,PDO::PARAM_STR))); + $res = $co->getResults(); + foreach($res as $row){ + $tabList[]= new Liste($row['id'],$row['nom'],$nom,array()); + } + $co->executeQuery($queryUser, array('nom' => array($nom, PDO::PARAM_STR))); - $results = $co->getResults(); + $results = $co->getResults(); - Foreach($results as $row){ - $usr = new Utilisateur($row['id'], $row['nom'], $row['pwd']); - } - } - catch(PDOException $Exception){ - echo 'erreur'; - echo $Exception->getMessage(); + foreach($results as $row){ + $usr = new Utilisateur($row['nom'], $row['pwd'],$tabList); } } + catch(PDOException $Exception){ + echo 'erreur'; + echo $Exception->getMessage(); + } return $usr; } diff --git a/modeles/Modele/ListModel.php b/modeles/Modele/ListModel.php new file mode 100644 index 0000000..0f0017b --- /dev/null +++ b/modeles/Modele/ListModel.php @@ -0,0 +1,25 @@ +listgw = new ListeGateway($co); + } + + function creerListe(string $nom, $private){ + if(isset($_SESSION['login'])){ + if($private="on"){ + $this->listgw->creerListe($nom,$_SESSION['login']); + }else{ + $this->listgw->creerListe($nom,null); + } + }else{ + $this->listgw->creerListe($nom,null); + } + } +} + +?> \ No newline at end of file diff --git a/modeles/Modele/UserModel.php b/modeles/Modele/UserModel.php index 6f8a05a..d77b792 100644 --- a/modeles/Modele/UserModel.php +++ b/modeles/Modele/UserModel.php @@ -4,29 +4,35 @@ class UserModel{ public $listgw; public $usergw; - public function __construct(){ - $co = new Connection(); + 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 deconnection(){ + function deconnection(){ session_unset(); session_destroy(); $_SESSION = array(); } - public function creerListePv($nom,$idCeator){ + function creerListePv($nom,$idCeator){ $this->listgw->creerListe($nom,$idCreator); } - public function desinscription($login){ + function desinscription($login){ $this->usergw->delUtilisateur($login); } - public function changerPassword($newPassword){ + function changerPassword($newPassword){ $this->usergw->putPassword($newPassword); } + + function pullListesPrivees($nom){ + $listes=$this->listgw->getByCreator($nom); + return $listes; + } } ?> \ No newline at end of file diff --git a/modeles/Modele/VisiteurModel.php b/modeles/Modele/VisiteurModel.php index 7398b04..d1bad16 100644 --- a/modeles/Modele/VisiteurModel.php +++ b/modeles/Modele/VisiteurModel.php @@ -1,39 +1,42 @@ gtwUsr = new UserGateway($co); $this->gtwListe = new ListeGateway($co); } - public function get_gtwUsr(): UserGateway { - return $this->gtwUsr; + public function getHashedPassword(string $usr){ + return $this->gtwUsr->getHashedPassword($usr); } - public function get_gtwListe(): ListeGateway { - return $this->gtwListe; - } - - public function connexion($login, $mdp){ - $results = $this->get_gtwUsr()->getUtilisateurbyNameAndPassword($login, $mdp); - if ($results != NULL){ - $_SESSION['role'] = 'user'; - $_SESSION['login'] = $login; + public function existUser(string $usr):bool{ + if($this->gtwUsr->getUtilisateurNom($usr) != null){ return true; } return false; } - public function inscription($login, $mdp){ - $this->get_gtwUsr()->creerUtilisateur($login, $mdp); + public function connexion($login){ + $_SESSION['role'] = 'Utilisateur'; + $_SESSION['login'] = $login; } - public function creerListe($nom) { - $this->get_gtwListe()->creerListe($nom, NULL); + 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) { diff --git a/modeles/Métier/Liste.php b/modeles/Métier/Liste.php index f4103f5..f731528 100644 --- a/modeles/Métier/Liste.php +++ b/modeles/Métier/Liste.php @@ -1,27 +1,17 @@ id=$i; $this->nom=$n; + $this->nomCreateur=$nomCrea; $this->taches=$t; } - - function get_id(): int { - return $this->id; - } - - function get_nom(): string { - return $this->nom; - } - - function get_idCreator(): array { - return $this->taches; - } } ?> \ No newline at end of file diff --git a/modeles/Métier/Tache.php b/modeles/Métier/Tache.php index cec783c..123f746 100644 --- a/modeles/Métier/Tache.php +++ b/modeles/Métier/Tache.php @@ -1,31 +1,16 @@ id = $i; - $this->intitule = $in; + $this->nom = $in; $this->isCompleted = $is; - } - - function get_id(): int { - return $this->id; - } - - function get_intitule(): string { - return $this->intitule; - } - - function get_isCompleted(): boolean { - return $this->isCompleted; - } - - function get_idListe(): string { - return $this->idListe; + $this->idListe=$idListe; } } diff --git a/modeles/Métier/Utilisateur.php b/modeles/Métier/Utilisateur.php index 72bf17f..7c3297e 100644 --- a/modeles/Métier/Utilisateur.php +++ b/modeles/Métier/Utilisateur.php @@ -1,13 +1,11 @@ id=$i; + function __construct(string $n, string $p, $liste) { $this->nom=$n; $this->password=$p; $this->listListe=$liste; diff --git a/vues/.DS_Store b/vues/.DS_Store new file mode 100644 index 0000000..d3f29c9 Binary files /dev/null and b/vues/.DS_Store differ diff --git a/vues/acceuil.php b/vues/acceuil.php index cf02a81..1b829ca 100644 --- a/vues/acceuil.php +++ b/vues/acceuil.php @@ -8,17 +8,58 @@