From 8d36530eb50f80bd0d2b77e03ff716c4776f5cfc Mon Sep 17 00:00:00 2001 From: Lucie Bedouret Date: Wed, 7 Dec 2022 16:35:46 +0100 Subject: [PATCH] =?UTF-8?q?ADD=20:=20toutes=20les=20m=C3=A9thodes=20du=20c?= =?UTF-8?q?ontrolleur=20et=20du=20mod=C3=A8le=20de=20l'utilisateur=20conne?= =?UTF-8?q?ct=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controleurs/ControleurUtilisateur.php | 77 +++++++++++++++------------ modeles/Modele/UserModel.php | 4 ++ 2 files changed, 47 insertions(+), 34 deletions(-) diff --git a/controleurs/ControleurUtilisateur.php b/controleurs/ControleurUtilisateur.php index 50dd5d7..84260f2 100644 --- a/controleurs/ControleurUtilisateur.php +++ b/controleurs/ControleurUtilisateur.php @@ -8,34 +8,30 @@ class UserController{ session_sart(); $arrayErrorViews= array(); - try{ - $action = $_REQUEST['action']??null; - switch($action){ - case "deconnection": - $this->deconnection($arrayErrorViews); - break; - case "creerListePv": - $this->creerListe($arrayErrorViews); - break; - case "desinscription": - $this->desinctription($arrayErrorViews); - break; - case "changerInfos": - $this->changerInfos($arrayErrorViews); - break; - default : - $arrayErrorViews[]="Erreur innatendue !!!"; - require($rep.$vues['error']); - } - }catch(PDOException $e){ - $dataView[]="Erreur inatendue"; - require($rep.$vues['erreur']); + $action = $_REQUEST['action']??null; + switch($action){ + case "deconnection": + $this->deconnection($arrayErrorViews); + break; + case "creerListePv": + $this->creerListe($arrayErrorViews); + break; + case "desinscription": + $this->desinctription($arrayErrorViews); + break; + case "changerInfos": + $this->changerPassword($arrayErrorViews); + break; + default : + $arrayErrorViews[]="Erreur innatendue !!!"; + require($rep.$vues['error']); } } public function deconnection($arrayErrorViews){ // appeler la méthode deco du modèle - UserModel::deconnection(); + $retour = UserModel::deconnection(); + require($rep.$vues['acceuil']); } public function creerListePv($arrayErrorViews){ @@ -50,22 +46,35 @@ class UserController{ //Validation::clear_string($_POST['ListName']); // appelle à la methode du modèle if($privee == true){ - UserModel::creerListePv($nomListe,$_SESSION['login']); + try{ + UserModel::creerListePv($nomListe,$_SESSION['login']); + } catch (PDOException $e){ + $dataView[]="Erreur inatendue"; + require($rep.$vues['erreur']); + } }else{ - VisitorModel::creerListe($nomListe); + try{ + VisitorModel::creerListe($nomListe); + } catch (PDOException $e){ + $dataView[]="Erreur inatendue"; + require($rep.$vues['erreur']); + } } } - public function desinscription($arrayErrorViews){ + public function changerPassword($arrayErrorViews){ global $rep, $vues; - // recup valeurs des champs - $password=$_POST['password']; - // valider les champs - Validation::val_desinscription($password); - // vider les champs - //Validation::clear_string($_POST['password']); - // appel à la classe userModel - UserModel::desinscription($_SESSION['login']); + $password1=$_POST['password1']; + $passwordConfirm=$_POST['passwordConfirm']; + $newPassword=Validation::val_changer_password($password1,$passwordConfirm); + + try{ + UserModel::changerPassword($newPassword); + require($rep.$vues['profil']) + }catch(PDOException $e){ + $dataView[]="Erreur inatendue"; + require($rep.$vues['erreur']); + } } } diff --git a/modeles/Modele/UserModel.php b/modeles/Modele/UserModel.php index 08841dc..6f8a05a 100644 --- a/modeles/Modele/UserModel.php +++ b/modeles/Modele/UserModel.php @@ -23,6 +23,10 @@ class UserModel{ public function desinscription($login){ $this->usergw->delUtilisateur($login); } + + public function changerPassword($newPassword){ + $this->usergw->putPassword($newPassword); + } } ?> \ No newline at end of file