From 6c75200b8cd168e5f5c670cf797e346b47c77a67 Mon Sep 17 00:00:00 2001 From: beaulaton Date: Wed, 15 Jan 2025 14:38:05 +0100 Subject: [PATCH] Suppression d'un compte utilisateur --- config/config.php | 2 +- src/Controleur/FrontControler.php | 3 +- src/Controleur/UserControler.php | 72 ++++++++++++++++++++++++----- src/Controleur/VisitorControler.php | 4 +- src/Gateway/UserGateway.php | 20 +++++++- src/Model/UserModel.php | 16 +++++++ vue/templates/login.html.twig | 2 +- vue/templates/profil.html.twig | 6 +++ 8 files changed, 106 insertions(+), 19 deletions(-) diff --git a/config/config.php b/config/config.php index 18ac15c..836d703 100644 --- a/config/config.php +++ b/config/config.php @@ -14,7 +14,7 @@ $mdp = ''; -$racine='/~kekentin/WF/WF-Website'; // /~kekentin/WF/WF-Website /~lebeaulato/WF-Website /~kemondejar/WF-Website +$racine='/~lebeaulato/WF-Website'; // /~kekentin/WF/WF-Website /~lebeaulato/WF-Website /~kemondejar/WF-Website //$racine='/WF-Website'; diff --git a/src/Controleur/FrontControler.php b/src/Controleur/FrontControler.php index e38d0c8..2ec4320 100644 --- a/src/Controleur/FrontControler.php +++ b/src/Controleur/FrontControler.php @@ -16,7 +16,7 @@ Class FrontControler{ global $twig,$racine; $this->listAction = ['visitor' => array('accueil','search','quote','login','signin','validlogin','validsignin'), - 'user' => array('quiz','commentary','logout','addComment','favorite','profil','addFav','supFav','changedata', 'submit', 'validsubmit', 'add'), + 'user' => array('quiz','commentary','logout','addComment','favorite','profil','addFav','supFav','changedata', 'submit', 'validsubmit', 'add','deleteAccount'), 'admin' => array('null')]; $dVueEreur = []; @@ -54,6 +54,7 @@ Class FrontControler{ $router->map('GET|POST', '/submit', 'UserControler', 'submit'); $router->map('GET|POST', '/validsubmit', 'UserControler', 'validsubmit'); $router->map('GET|POST', '/add', 'UserControler', 'add'); + $router->map('GET|POST', '/deleteAccount', 'UserControler', 'deleteAccount'); $match = $router->match(); diff --git a/src/Controleur/UserControler.php b/src/Controleur/UserControler.php index 98e3178..5a4b9f5 100644 --- a/src/Controleur/UserControler.php +++ b/src/Controleur/UserControler.php @@ -437,6 +437,7 @@ class UserControler { return null; } + public function add(){ global $vues; var_dump($_POST); @@ -504,20 +505,67 @@ class UserControler { } - public function sendEmailChangeLogin(string $email) : void{ - $to = $email; // Adresse email de destination - $subject = "What The Fantasy - Changement d'Email"; // Sujet de l'email - $message = " - Bonjour, + + // ===================== DELETE ACCOUNT FUNCTION ===================== + + public function deleteAccount(){ + $this->uMod->deleteAllCommentary($_SESSION["user"]); // Delete all commentary + $this->uMod->deleteAllFavorite($_SESSION["user"]); // Delete all favorite + $this->uMod->deleteAccount($_SESSION["user"]); + $this->unlog(); + } + + + // ===================== EMAIL FUNCTION ===================== + + public function sendEmailChangeLogin(string $email) { + // Génère les données du message + $sujet = "What The Fantasy - Changement d'Email"; + $urlImage = "public/images/Baneer.png"; + + + // Génère une frontière unique pour l'email + $boundary = "-----=" . md5(uniqid(mt_rand())); + + //Instancie les headers + $headers = "From: noreply@whatTheFantasy.com\r\n"; + $headers .= "MIME-Version: 1.0\r\n"; + $headers .= "Content-Type: multipart/related; boundary=\"$boundary\"\r\n"; + - L'adresse mail $email est désormais votre nouvelle adresse. + // Corps de l'email HTML avec l'image intégrée + $corpsMessage = "--$boundary\r\n"; + $corpsMessage .= "Content-Type: text/html; charset=UTF-8\r\n"; + $corpsMessage .= "Content-Transfer-Encoding: 8bit\r\n\r\n"; - - L'équipe du site - "; // Contenu de l'email - $headers = "From: noreply@whatTheFantasy.com"; // Adresse email de l'expéditeur + // Ajoute le message HTML + $corpsMessage .= " + + \"Image\" +

Bonjour,

+ +

Vous venez de changer votre adresse mail. Dorénavant, votre email sera $email.

+

L'équipe du site

+ + \r\n"; + + // Ajoute l'image en pièce jointe + $corpsMessage .= "--$boundary\r\n"; + $corpsMessage .= "Content-Type: image/jpeg; name=\"image.jpg\"\r\n"; + $corpsMessage .= "Content-Transfer-Encoding: base64\r\n"; + $corpsMessage .= "Content-ID: \r\n\r\n"; + + + $imageContent = file_get_contents($urlImage);// Lecture et encodage de l'image en base64 + if ($imageContent === false) { + return "Impossible de charger l'image spécifiée."; + } + $corpsMessage .= chunk_split(base64_encode($imageContent)) . "\r\n"; - // Envoyer l'email - mail($to, $subject, $message, $headers); + + $corpsMessage .= "--$boundary--";// Fin du corps de l'email + + + mail($email, $sujet, $corpsMessage, $headers);// Envoi de l'email } } diff --git a/src/Controleur/VisitorControler.php b/src/Controleur/VisitorControler.php index 523c3c5..87cb3ee 100644 --- a/src/Controleur/VisitorControler.php +++ b/src/Controleur/VisitorControler.php @@ -232,7 +232,7 @@ Class VisitorControler { // Ajoute le message HTML $corpsMessage .= " - \"Image\" + \"Image\"

Bonjour $pseudo,

Merci de vous être inscrit sur notre site What The Fantasy. C’est avec grande joie que nous vous accueillons au sein de notre confrérie, pour découvrir ensemble... @@ -242,7 +242,7 @@ Class VisitorControler { \r\n"; - // Ajoute l'image en pièce jointe avec un CID + // Ajoute l'image en pièce jointe $corpsMessage .= "--$boundary\r\n"; $corpsMessage .= "Content-Type: image/jpeg; name=\"image.jpg\"\r\n"; $corpsMessage .= "Content-Transfer-Encoding: base64\r\n"; diff --git a/src/Gateway/UserGateway.php b/src/Gateway/UserGateway.php index f66e9a1..ec91f2b 100644 --- a/src/Gateway/UserGateway.php +++ b/src/Gateway/UserGateway.php @@ -75,14 +75,30 @@ Class UserGateway extends Gateway{ $query = 'SELECT id_user FROM Users WHERE username = :username'; $this->co->executeQuery($query, array(':username' => array($username,PDO::PARAM_STR))); $result = $this->co->getResults()[0]['id_user']; - var_dump($result); - var_dump($id); + $query = 'DELETE FROM Favorite WHERE users = :user AND quote = :id;'; $this->co->executeQuery($query, array(':user' => array($result,PDO::PARAM_INT), ':id' => array($id,PDO::PARAM_INT))); $query = 'UPDATE Quote SET likes = (likes - 1) WHERE id_quote = :id'; $this->co->executeQuery($query, array(':id' => array($id,PDO::PARAM_INT))); } + + public function deleteAllCommentaryUser(string $user){ + $query = 'DELETE FROM Commentary WHERE users IN ( SELECT id_user FROM Users WHERE username = :user);'; + $this->co->executeQuery($query, array(':user'=>array($user, PDO::PARAM_STR))); + } + + + public function deleteAllFavoriteUser(string $user){ + $query = 'DELETE FROM Favorite WHERE users IN ( SELECT id_user FROM Users WHERE username = :user);'; + $this->co->executeQuery($query, array(':user'=>array($user, PDO::PARAM_STR))); + } + + public function deleteUser(string $user){ + $query = 'DELETE FROM Users WHERE username=:user;'; + $this->co->executeQuery($query, array(':user'=>array($user, PDO::PARAM_STR))); + } + // ===================== GET FUNCTION ===================== public function getFavorite(string $id):array{ diff --git a/src/Model/UserModel.php b/src/Model/UserModel.php index 5dd1edc..96293bd 100644 --- a/src/Model/UserModel.php +++ b/src/Model/UserModel.php @@ -170,6 +170,22 @@ public function supFavorite(string $username, int $id){ $this->gateway->supFavorite($username,$id); } + + + + // ===================== DELETE FUNCTION ===================== + + public function deleteAllCommentary(string $username){ + $this->gateway->deleteAllCommentaryUser($username); + } + + public function deleteAllFavorite(string $username){ + $this->gateway->deleteAllFavoriteUser($username); + } + + public function deleteAccount(string $username){ + $this->gateway->deleteUser($username); + } } ?> diff --git a/vue/templates/login.html.twig b/vue/templates/login.html.twig index a9f8594..0830899 100644 --- a/vue/templates/login.html.twig +++ b/vue/templates/login.html.twig @@ -6,7 +6,7 @@

Mot de passe *

- + {% if error is defined and error is not empty %}

{{ error }}

diff --git a/vue/templates/profil.html.twig b/vue/templates/profil.html.twig index a8b1b4d..92ad00b 100644 --- a/vue/templates/profil.html.twig +++ b/vue/templates/profil.html.twig @@ -55,6 +55,12 @@ + +