diff --git a/src/.htaccess b/src/.htaccess index a8b8331..c73690a 100644 --- a/src/.htaccess +++ b/src/.htaccess @@ -12,4 +12,4 @@ RewriteEngine On RewriteRule ^login$ index.php?action=redirectionLogin [L] RewriteRule ^inscription$ index.php?action=redirectionInscription [L] -RewriteRule ^VueListePublic$ index.php?action=redirectionListePublic [L] +RewriteRule ^VueListePublic$ index.php?action=redirectionListePublic [L] \ No newline at end of file diff --git a/src/controller/CtrlVisiteur.php b/src/controller/CtrlVisiteur.php index c642aa3..e9a6c19 100644 --- a/src/controller/CtrlVisiteur.php +++ b/src/controller/CtrlVisiteur.php @@ -59,13 +59,13 @@ class CtrlVisiteur { } catch (PDOException $e) { //si erreur BD, pas le cas ici - $dVueEreur[] = "Erreur BD!!! "; + $dVueEreur[] = "Erreur: Connexion a la base de données impossible! "; require ($rep.$vues['erreur']); } - catch (Exception $e2) + catch (Exception $e) { - $dVueEreur[] = "Erreur inattendue!!! "; + $dVueEreur[] = "Erreur venue de nulle part"; require ($rep.$vues['erreur']); } @@ -98,34 +98,43 @@ class CtrlVisiteur { function seConnecter(array $dVueEreur) { global $rep,$vues; - MdlVisiteur::Connection(); - $action=NULL; - $this->ConsulterListePublic($dVueEreur); + try{ + $result=MdlUtilisateur::Connection(); + $action=NULL; + $this->ConsulterListePublic($dVueEreur); + } + catch (Exception $e) + { + $ErreurLog=$e->getMessage(); + require ($rep.$vues['login']); + } + } function ConsulterListePublic(array $dVueEreur) { global $rep,$vues; $listes = MdlVisiteur::RecupererListePublic(); $taches = MdlVisiteur::RecupererTache(); + $action=NULL; require ($rep.$vues['listPublic']); } function SupprimerTache(){ global $rep,$vues; - $id = $_GET['idTache']; - $tache = MdlVisiteur::SupprimerTache($id); + $tache = MdlVisiteur::SupprimerTache(); $listes = MdlVisiteur::RecupererListePublic(); $taches = MdlVisiteur::RecupererTache(); + $action=NULL; require ($rep.$vues['listPublic']); } function SupprimerListe(){ global $rep,$vues; - $id = $_GET['idListe']; - $liste = MdlVisiteur::SupprimerListe($id); + $liste = MdlVisiteur::SupprimerListe(); $listes = MdlVisiteur::RecupererListePublic(); $taches = MdlVisiteur::RecupererTache(); + $action=NULL; require ($rep.$vues['listPublic']); } diff --git a/src/controller/FrontControleur.php b/src/controller/FrontControleur.php index 3bd8d7b..ffd4492 100644 --- a/src/controller/FrontControleur.php +++ b/src/controller/FrontControleur.php @@ -14,7 +14,7 @@ class FrontControleur { // $action=$_REQUEST['action']; // //On vérifie si l'action fait partie des listes d'actions - // $string_actor=fct($action,$listeActions); + // $string_actor=quelListe($action,$listeActions); // if($string_actor!=NULL){ // $mdl=new mdl.$string_actor; // $actor=$mdl.isMdl; @@ -34,7 +34,16 @@ class FrontControleur { $dVueEreur[] = "Erreur inattendue!!! "; require ($rep.$vues['erreur']); } - } + + public static function quelListe($action,$listeActions){ + foreach($listeActions as $a){ + if(in_array($action, $a)){ + return array_search($a,$listeActions); + } + } + return null; + } + } ?> diff --git a/src/modele/MdlUtilisateur.php b/src/modele/MdlUtilisateur.php index 22d5317..e314da2 100644 --- a/src/modele/MdlUtilisateur.php +++ b/src/modele/MdlUtilisateur.php @@ -7,16 +7,23 @@ class MdlUtilisateur } - public static function CreerUtilisateur(){ - global $dVueEreur; - $userGtw = new UtilisateurGateway(); - // $verif = Validation::val_form_user($_POST["nom-Form"],$_POST["prenom-Form"],$_POST["pseudo-Form"],$_POST["password-Form"],$_POST["mail-Form"],$dVueEreur); - // if($verif == false){ - // throw new Exception(); - // } - // $hash = password_hash($_POST[password-Form], PASSWORD_DEFAULT); - $userGtw->AjouterUtilisateur($_POST["nom-Form"],$_POST["prenom-Form"],$_POST["pseudo-Form"],$_POST["mail-Form"],$_POST["password-Form"]); - } + public function connection(){ + $gtw=new UtilisateurGateway(); + $mail=Validation::cleanString($_POST['mail']); + $mdp=Validation::cleanString($_POST['password']); + $verif_pass=$gtw->getCredentials($mail); + if(password_verify($mdp,$verif_pass)){ + $userCurrent=$gtw->RechercheUtilisateurViaEmail($mail); + $_SESSION['role']='user'; + $_SESSION['id']=$userCurrent->getId(); + $_SESSION['nom']=$userCurrent->getNom(); + $_SESSION['prenom']=$userCurrent->getPrenom(); + $_SESSION['pseudo']=$userCurrent->getPseudo(); + $_SESSION['email']=$userCurrent->getMail(); + return $userCurrent; + } + else throw new Exception('Mot de passe incorrect*'); + } public static function RecupererListePublic(){ $userGtw = new ListeGateway(); diff --git a/src/modele/MdlVisiteur.php b/src/modele/MdlVisiteur.php index 158706d..b5a2bdb 100644 --- a/src/modele/MdlVisiteur.php +++ b/src/modele/MdlVisiteur.php @@ -26,20 +26,21 @@ class MdlVisiteur public static function RecupererTache(){ $userGtw = new TacheGateway(); - return $userGtw->getTache(); } - public static function SupprimerTache(string $id){ - $userGtw = new TacheGateway(); - - return $userGtw->Supprimer($id); + public static function SupprimerTache(){ + $userGtw = new TacheGateway(); + $id = $_GET['idTache']; + $userGtw->Supprimer($id); } - public static function SupprimerListe(string $id){ - $userGtw = new ListeGateway(); - - return $userGtw->Supprimer($id); + public static function SupprimerListe(){ + $userGtw = new ListeGateway(); + $taskGtw = new TacheGateway(); + $id = $_GET['idListe']; + $taskGtw->SupprimerViaListe($id); + $userGtw->Supprimer($id); } } diff --git a/src/modele/gateway/ListeGateway.php b/src/modele/gateway/ListeGateway.php index 5e4ec24..17752d3 100644 --- a/src/modele/gateway/ListeGateway.php +++ b/src/modele/gateway/ListeGateway.php @@ -22,7 +22,7 @@ class ListeGateway{ } public function Supprimer(int $id){ - $query='DELETE FROM ToDoList_Liste WHERE id=:id'; + $query="DELETE FROM ToDoList_Liste WHERE id=:id"; $this->con->executeQuery($query,array('id' => array($id, PDO::PARAM_INT))); } @@ -33,13 +33,6 @@ class ListeGateway{ return $listes; } - public function getTacheListe(Liste $liste){ - $query = 'SELECT tache FROM ToDoList_Liste WHERE id=:id '; - $this->con->executeQuery($query, array('id' => array($liste->getId, PDO::PARAM_INT))); - $results=$this->con->getResults(); - return $results; - } - public function getListePublic($offset,$limit){ $query = "SELECT * FROM ToDoList_Liste WHERE estPublic LIMIT $offset, $limit"; $this->con->executeQuery($query); diff --git a/src/modele/gateway/TacheGateway.php b/src/modele/gateway/TacheGateway.php index 1610903..20a7268 100644 --- a/src/modele/gateway/TacheGateway.php +++ b/src/modele/gateway/TacheGateway.php @@ -25,6 +25,12 @@ class TacheGateway{ $this->con->executeQuery($query,array('id' => array($id, PDO::PARAM_INT))); } + // Si une liste est supprimée on supprime toutes ces tâches grâce à cette fonction + public function SupprimerViaListe(string $id){ + $query='DELETE FROM ToDoList_Tache WHERE idListe=:id'; + $this->con->executeQuery($query,array('id' => array($id, PDO::PARAM_INT))); + } + public function getTache(){ $query='SELECT * FROM ToDoList_Tache'; $this->con->executeQuery($query); diff --git a/src/modele/gateway/UtilisateurGateway.php b/src/modele/gateway/UtilisateurGateway.php index 3631a96..42dd98b 100644 --- a/src/modele/gateway/UtilisateurGateway.php +++ b/src/modele/gateway/UtilisateurGateway.php @@ -23,20 +23,27 @@ class UtilisateurGateway{ 'id' => array($id, PDO::PARAM_INT))); } - public getCredential(string $id){ - $query = 'SELECT motDePasse FROM ToDoList_Utilisateur WHERE id=:id'; - - if(this->con->executeQuery($query, array('id' => array($id, PDO::PARAM_INT)))){ - return (this->con->getResults[0]['motDePasse']) - } - else{ - /* pas sur de ça*/ - throw new PDOexception; + public function getCredentials(string $mail){ + $query = 'SELECT motDePasse FROM ToDoList_Utilisateur WHERE email=:mail'; + $this->con->executeQuery($query, array('mail' => array($mail, PDO::PARAM_STR))); + $results=$this->con->getResults(); + if($results!=null){ + return $results[0]['motDePasse']; + }else{ + throw new Exception("Identifiant introuvable*"); } + } - public function RechercheUtilisateurViaEmail(string $pseudo){ - + public function RechercheUtilisateurViaEmail(string $mail){ + $query = 'SELECT * FROM ToDoList_Utilisateur WHERE email=:mail'; + $this->con->executeQuery($query, array('mail' => array($mail, PDO::PARAM_INT))); + $results=$this->con->getResults(); + if($results!=null){ + return new Utilisateur($results[0]['id'],$results[0]['nom'],$results[0]['prenom'],$results[0]['pseudo'],$results[0]['email']); + }else{ + throw new Exception("Identifiant introuvable*"); + } } } ?> \ No newline at end of file diff --git a/src/modele/metier/Admin.php b/src/modele/metier/Admin.php deleted file mode 100644 index 4de71ce..0000000 --- a/src/modele/metier/Admin.php +++ /dev/null @@ -1,65 +0,0 @@ -id = $id; - $this->nom = $nom; - $this->prenom = $prenom; - $this->pseudo = $pseudo; - $this->email = $email; - } - - //Nom - public function getId(){ - return $this->id; - } - - public function setId($id){ - $this->nom = $id; - } - - //Nom - public function getNom(){ - return $this->nom; - } - - public function setNom($nom){ - $this->nom = $nom; - } - - //Prenom - public function getPrenom(){ - return $this->prenom; - } - - public function setPrenom($prenom){ - $this->prenom = $prenom; - } - - //Pseudo - public function getPseudo(){ - return $this->pseudo; - } - - public function setPseudo($pseudo){ - $this->pseudo = $pseudo; - } - - //mail - public function getMail(){ - return $this->email; - } - - public function setEmail($email){ - $this->email = $email; - } - -} -?> \ No newline at end of file diff --git a/src/modele/metier/Utilisateur.php b/src/modele/metier/Utilisateur.php index a526b81..41c9d32 100644 --- a/src/modele/metier/Utilisateur.php +++ b/src/modele/metier/Utilisateur.php @@ -7,15 +7,13 @@ class Utilisateur private $prenom; private $pseudo; private $email; - private $isAdmin; - public function __construct($id, $nom, $prenom, $pseudo, $email, $motDePasse, $isAdmin){ + public function __construct($id, $nom, $prenom, $pseudo, $email){ $this->id = $id; $this->nom = $nom; $this->prenom = $prenom; $this->pseudo = $pseudo; $this->email = $email; - $this->isAdmin = $isAdmin; } //Nom diff --git a/src/vue/Images/trash.png b/src/vue/Images/trash.png index 8d541ad..b2c0b0e 100644 Binary files a/src/vue/Images/trash.png and b/src/vue/Images/trash.png differ diff --git a/src/vue/css/style.css b/src/vue/css/style.css index bb3129c..56b4aa6 100644 --- a/src/vue/css/style.css +++ b/src/vue/css/style.css @@ -282,7 +282,10 @@ body::before { transition: background .5s; } - +.ErreurText{ + color: red; + font-size: 0.7rem; +} .button{ border-color: #38b6ff; diff --git a/src/vue/html/NavBar.php b/src/vue/html/NavBar.php index 21c1886..f61673e 100644 --- a/src/vue/html/NavBar.php +++ b/src/vue/html/NavBar.php @@ -17,8 +17,8 @@