diff --git a/config/config.php b/config/config.php index e46ccb7..f397fb7 100644 --- a/config/config.php +++ b/config/config.php @@ -18,6 +18,7 @@ $racine='/~kemondejar/WF-Website'; // /~kekentin/WF/WF-Website /~lebeaulato/WF-W $repImg='/home/UCA/kemondejar/public_html/WF-Website/public/images/'; //$repImg='/'; + //Vues $vues['erreur'] = 'vue/erreur.php'; $vues['accueil'] = 'vue/accueil.php'; diff --git a/public/images/Baneer.png b/public/images/Baneer.png new file mode 100644 index 0000000..9c60579 Binary files /dev/null and b/public/images/Baneer.png differ diff --git a/public/script/changeData.js b/public/script/changeData.js index c9a3583..187346d 100644 --- a/public/script/changeData.js +++ b/public/script/changeData.js @@ -114,4 +114,44 @@ function editFieldPassWd(id) { pElement.appendChild(saveButton); inputNewPass.focus();// Mettre le focus sur le premier champ de saisie +} +function editFieldImage(id,path) { + var pElement = document.getElementById('imagePost'); + + var inputImage = document.createElement('input'); + inputImage.type = 'hidden'; + inputImage.name='image'; + inputImage.value=id; + + + var buttonSubmit = document.createElement('button'); + buttonSubmit.textContent = 'Valider'; + buttonSubmit.classList.add('saveButtonPasswd'); + buttonSubmit.type ="submit"; + + pElement.innerHTML = ''; + pElement.appendChild(inputImage); + pElement.appendChild(buttonSubmit); + + inputImage.focus(); // Mettre le focus sur le champ de saisie + + /////////////////////////////////////////////// + + var pEle = document.getElementById('image'); + + var image = document.createElement('img'); + image.src=path; + image.classList.add('imageProfil'); + + var popover = document.getElementById("list-ChangeImg"); + popover.hidePopover(); + + var button = document.createElement('button'); + button.popoverTargetElement= popover; + button.name="image"; + button.classList.add('ChangeImg'); + button.appendChild(image); + + pEle.innerHTML = ''; + pEle.appendChild(button); } \ No newline at end of file diff --git a/public/styles/styleProfil.css b/public/styles/styleProfil.css index abca93f..b459c22 100644 --- a/public/styles/styleProfil.css +++ b/public/styles/styleProfil.css @@ -9,6 +9,10 @@ body.dark-mode p{ color : var(--main-dark-text-color); } +body.dark-mode :popover-open { + background: var(--main-dark-gradient); + color: var(--main-dark-text-color); +} body.dark-mode .buttonSudmite{ background: var(--main-dark-gradient); @@ -49,6 +53,11 @@ body.light-mode p{ } +body.light-mode :popover-open { + background: var(--main-light-gradient); + color: var(--main-light-text-color); +} + body.light-mode .buttonSubmit{ background: var(--main-light-gradirent); color: var(--main-light-text-color); @@ -91,6 +100,17 @@ p{ font-family: "Lemon", serif; } +::backdrop { + backdrop-filter: blur(3px); +} +:popover-open { + width: 70%; + height: 60%; + font-size: 15px; + text-align: center; + font-family: "Lemon", serif; + +} .buttonSudmite{ font-family: "Lemon", serif; diff --git a/src/Controleur/UserControler.php b/src/Controleur/UserControler.php index 4c31ace..a72dbd7 100644 --- a/src/Controleur/UserControler.php +++ b/src/Controleur/UserControler.php @@ -49,6 +49,7 @@ class UserControler { global $vues; $p = $this->uMod->getUsername($_SESSION["user"]); + $listImg = $this->iMod->getAllImg() ; // Pour les messages d'erreur $error_message = null; @@ -121,8 +122,7 @@ class UserControler { * @throws RuntimeError * @throws LoaderError */ - public function continueQuiz(int $id_quiz, int $total_questions) : void - { + public function continueQuiz(int $id_quiz, int $total_questions) : void{ global $racine; $score = $_SESSION['score']; $_SESSION['no_question'] = Verification::verifChar( isset($_SESSION['no_question']) ? ($_SESSION['no_question'] + 1) : 1); @@ -140,8 +140,7 @@ class UserControler { * @throws RuntimeError * @throws LoaderError */ - public function endQuiz(int $id_quiz, int $score) : void - { + public function endQuiz(int $id_quiz, int $score) : void{ global $vues,$co; $gw = new QuizGateway($co); @@ -155,8 +154,7 @@ class UserControler { require_once $vues['endQuiz']; } - public function CorrectAnswer() : bool - { + public function CorrectAnswer() : bool{ $answera = Verification::verifChar($_POST['answera'] ?? null); $answerb = Verification::verifChar($_POST['answerb'] ?? null); $answerc = Verification::verifChar($_POST['answerc'] ?? null); @@ -182,8 +180,7 @@ class UserControler { return $answer == $res->getCanswer(); } - public function GetQuestion(int $id): array - { + public function GetQuestion(int $id): array{ global $co; $gw = new QuizQuestionGateway($co); $mdl = new QuizQuestionModel($gw); @@ -195,8 +192,7 @@ class UserControler { * @throws SyntaxError * @throws LoaderError */ - public function showQuestion(int $id, int $num) : void - { + public function showQuestion(int $id, int $num) : void{ global $vues,$twig; $q = $this->GetQuestion($id); $question = $q[$num] ?? $q[0]; @@ -208,8 +204,7 @@ class UserControler { } - public function getNumberOfQuestion(int $id) : int - { + public function getNumberOfQuestion(int $id) : int{ global $co; $gw = new QuizGateway($co); $mdl = new QuizModel($gw); @@ -232,8 +227,8 @@ class UserControler { } - // ===================== UPDATE DATA USER FUNCTION ===================== + // ===================== UPDATE DATA USER FUNCTION ===================== public function changedata() : void{ global $vues, $racine; if ($_POST) @@ -251,12 +246,13 @@ class UserControler { } else if($newEmail){//Modif l'email $this->updateEmail($newEmail); + $this->sendEmailChangeLogin($newEmail); //Envoie un email confirmant le changement d'email } else if($newMdpFirst && $newMdpSecond){ //Modif le mot de passe $this->updatePassWd($oldPasswd, $newMdpFirst,$newMdpSecond); } else if($newImage){//Modif l'image - $this->updateImg(); + $this->updateImg($newImage); } } header("Location: ". $racine."/profil"); @@ -313,8 +309,8 @@ class UserControler { } } - public function updateImg(){ - $user = $this->uMod->setImage($_SESSION['user']); + public function updateImg(string $newImage){ + $user = $this->uMod->setImage($_SESSION['user'],$newImage); } @@ -328,8 +324,7 @@ class UserControler { * @throws RuntimeError * @throws LoaderError */ - public function submit() : void - { + public function submit() : void{ global $vues; $p = $this->caMod->getAllPerso(); $s = $this->srcMod->getAllSources(); @@ -341,6 +336,7 @@ class UserControler { * @throws RuntimeError * @throws LoaderError */ + public function toSubmit(string $content,string $character, string $source) { global $co; @@ -539,4 +535,21 @@ class UserControler { public function questionSuivantAleatoire(){ } + + 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, + + L'adresse mail $email est désormais votre nouvelle adresse. + + + L'équipe du site + "; // Contenu de l'email + $headers = "From: noreply@whatTheFantasy.com"; // Adresse email de l'expéditeur + + // Envoyer l'email + mail($to, $subject, $message, $headers); + } } diff --git a/src/Controleur/VisitorControler.php b/src/Controleur/VisitorControler.php index 0b57488..523c3c5 100644 --- a/src/Controleur/VisitorControler.php +++ b/src/Controleur/VisitorControler.php @@ -117,6 +117,7 @@ Class VisitorControler { public function validlogin() : void { + global $vues,$racine; if ($_POST) { @@ -131,7 +132,6 @@ Class VisitorControler { { $_SESSION['user'] = Verification::verifChar($pseudo); $_SESSION['role'] = 'user'; - //$this->sendEmailLogin($pseudo,$this->uMod->getEmailWithUser($pseudo)); Envoie un email pour chaque connexion header("Location: ". $racine); exit(); }else @@ -161,6 +161,7 @@ Class VisitorControler { { global $vues,$racine; + if ($_POST) { $pseudo = Verification::verifChar($_POST['pseudo'] ?? null); $email = Verification::verifChar($_POST['email'] ?? null); @@ -196,7 +197,9 @@ Class VisitorControler { exit(); } else echo $this->uMod->insertUser($pseudo, $email, $hmdp); - $this->sendEmailSignin($pseudo,$email); + + $this->sendEmailSubmit($email, $pseudo); + $_SESSION["role"] = Verification::verifChar('user'); $_SESSION["user"] = Verification::verifChar($pseudo); @@ -205,37 +208,58 @@ Class VisitorControler { } } - public function sendEmailSignin(string $pseudo, string $email) : void{ - $to = $email; // Adresse email de destination - $subject = "What The Fantasy - Création de compte"; // Sujet de l'email - $message = " - Bonjour $pseudo, + + function sendEmailSubmit(string $email, string $pseudo) { + // Génère les données du message + $sujet = "What The Fantasy - Création de compte"; + $urlImage = "public/images/Baneer.png"; + + + // Génère une frontière unique pour l'email + $boundary = "-----=" . md5(uniqid(mt_rand())); - 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... + //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"; + - À bientôt ! - L'équipe du site - "; // Contenu de l'email - $headers = "From: noreply@whatTheFantasy.com"; // Adresse email de l'expéditeur + // 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"; - // Envoyer l'email - mail($to, $subject, $message, $headers); - } - - public function sendEmailLogin(string $pseudo, string $email) : void{ - $to = $email; // Adresse email de destination - $subject = "What The Fantasy - Connexion à votre compte"; // Sujet de l'email - $message = " - Bonjour $pseudo, + // Ajoute le message HTML + $corpsMessage .= " + + \"Image\" +

Bonjour $pseudo,

- Nous avons détecté une connexion à votre compte $pseudo. Si cela vient de vous, vous pouvez ignorer ce message. Sinon, nous vous conseillons de changer votre mot de passe. +

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... +

+

À bientôt !

+

L'équipe du site

+ + \r\n"; - - L'équipe du site - "; // Contenu de l'email - $headers = "From: noreply@whatTheFantasy.com"; // Adresse email de l'expéditeur + // Ajoute l'image en pièce jointe avec un CID + $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"; + + + $corpsMessage .= "--$boundary--";// Fin du corps de l'email - // Envoyer l'email - mail($to, $subject, $message, $headers); + + mail($email, $sujet, $corpsMessage, $headers);// Envoi de l'email + } } \ No newline at end of file diff --git a/src/Entity/CharacterEntity.php b/src/Entity/CharacterEntity.php index e64ee67..e43cafe 100644 --- a/src/Entity/CharacterEntity.php +++ b/src/Entity/CharacterEntity.php @@ -70,8 +70,5 @@ class CharacterEntity $this->img_path = $img_path; } - - - } diff --git a/src/Entity/ImageEntity.php b/src/Entity/ImageEntity.php index 8bdf70a..1b9ea56 100644 --- a/src/Entity/ImageEntity.php +++ b/src/Entity/ImageEntity.php @@ -5,18 +5,16 @@ class ImageEntity { private int $idImg; private string $imgPath; - private string $isImgProfile; /** * @param int $idImg * @param string $imgPath * @param string $isImgProfile */ - public function __construct(int $idImg, string $imgPath, string $isImgProfile) + public function __construct(int $idImg, string $imgPath) { $this->idImg = $idImg; $this->imgPath = $imgPath; - $this->isImgProfile = $isImgProfile; } public function getIdImg(): int @@ -39,15 +37,5 @@ class ImageEntity $this->imgPath = $imgPath; } - public function getIsImgProfile(): string - { - return $this->isImgProfile; - } - - public function setIsImgProfile(string $isImgProfile): void - { - $this->isImgProfile = $isImgProfile; - } - } diff --git a/src/Entity/quizEntity.php b/src/Entity/QuizEntity.php similarity index 100% rename from src/Entity/quizEntity.php rename to src/Entity/QuizEntity.php diff --git a/src/Gateway/ImageGateway.php b/src/Gateway/ImageGateway.php index fd467da..4e6d0af 100644 --- a/src/Gateway/ImageGateway.php +++ b/src/Gateway/ImageGateway.php @@ -6,7 +6,7 @@ use PDO; class ImageGateway extends Gateway { - public function createImgGateway(int $idImg, string $imgPath, bool $isImgProfile) : bool + public function createImgGateway(int $idImg, string $imgPath) : bool { $query = " INSERT INTO Image @@ -22,8 +22,8 @@ class ImageGateway extends Gateway public function findImgById(int $idImg) : array { $query = " - SELECT * FROM Images - WHERE id_image = :id_img + SELECT * FROM Image + WHERE id_img = :id_img "; $this -> co -> executeQuery($query, ['id_img' => array($idImg, PDO::PARAM_INT)]); @@ -34,19 +34,7 @@ class ImageGateway extends Gateway public function findAllImg() : array { $query = " - SELECT * FROM Images - "; - - $this -> co -> executeQuery($query); - - return $this -> co -> getResults(); - } - - public function findAllImgProfile() : array - { - $query = " - SELECT * FROM Images - WHERE is_img_prfl + SELECT * FROM Image "; $this -> co -> executeQuery($query); @@ -57,8 +45,8 @@ class ImageGateway extends Gateway public function deleteImgGateway(int $idImg) : bool { $query = " - DELETE FROM Images - WHERE id_image = :id_img + DELETE FROM Image + WHERE id_img = :id_img "; return $this -> co -> executeQuery($query, ['id_img' => array($idImg, PDO::PARAM_INT)]); @@ -67,8 +55,8 @@ class ImageGateway extends Gateway public function updateImgGateway(int $idImg, string $imgPath) : bool { $query = " - UPDATE Images - SET img_path = :img_path + UPDATE Image + SET imgPath = :img_path WHERE id_image = :id_img "; diff --git a/src/Gateway/UserGateway.php b/src/Gateway/UserGateway.php index 27076f2..f66e9a1 100644 --- a/src/Gateway/UserGateway.php +++ b/src/Gateway/UserGateway.php @@ -182,8 +182,18 @@ Class UserGateway extends Gateway{ } - public function updateImg(string $username):array{ - $id_image = $this->randomImg(); + public function updateImg(string $username,string $newImage):array{ + if($newImage==null){ + $id_image = $this->randomImg(); + } + else if(is_int((int)$newImage)){ + $id_image=(int)$newImage; + } + else{ + $id_image = $this->randomImg(); + } + + //Update l'image du user passé en paramètre $query = 'UPDATE Users SET img=:id_image WHERE username=:username'; $this->co->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR), ':id_image'=> array($id_image, PDO::PARAM_INT))); diff --git a/src/Model/ImageModel.php b/src/Model/ImageModel.php index 4b1b046..74a8330 100644 --- a/src/Model/ImageModel.php +++ b/src/Model/ImageModel.php @@ -8,9 +8,9 @@ use Gateway\Gateway; class ImageModel extends Model { - public function createImgModel(int $idImg, string $imgPath, bool $isImgProfile) : bool + public function createImgModel(int $idImg, string $imgPath) : bool { - return $this -> gateway -> createImgGateway($idImg, $imgPath, $isImgProfile); + return $this -> gateway -> createImgGateway($idImg, $imgPath); } public function createImgModelWithoutId (string $imgPath) : int @@ -27,9 +27,8 @@ class ImageModel extends Model if ($res) { return new ImageEntity( - $res[0]['id_image'], - $res[0]['img_path'], - $res[0]['is_img_prfl'] + $res[0]['id_img'], + $res[0]['imgpath'] ); } return null; @@ -44,30 +43,13 @@ class ImageModel extends Model foreach ($res as $img) { $images[] = new ImageEntity( - $img['id_image'], - $img['img_path'], - $img['is_img_prfl'] + $img['id_img'], + $img['imgpath'] ); } return $images; } - public function getAllImgProfile() : array - { - $res = $this -> gateway -> findAllImgProfile(); - - $images = []; - - foreach ($res as $img) - { - $images[] = new ImageEntity( - $img['id_image'], - $img['img_path'], - $img['is_img_prfl'] - ); - } - return $images; - } public function deleteImgModel(int $idImg) : bool { diff --git a/src/Model/UserModel.php b/src/Model/UserModel.php index 0c38d21..5dd1edc 100644 --- a/src/Model/UserModel.php +++ b/src/Model/UserModel.php @@ -150,8 +150,8 @@ } - public function setImage(string $username){ - $res = $this->gateway->updateImg($username); + public function setImage(string $username,string $newImage){ + $res = $this->gateway->updateImg($username,$newImage); $src[] = $res[0]['img']; return $src; } diff --git a/vue/profil.php b/vue/profil.php index 8dc5208..a587a97 100644 --- a/vue/profil.php +++ b/vue/profil.php @@ -17,5 +17,6 @@ 'srcEmail' => $p->getEmail(), 'srcImg' => $p->getImgPrfl(), 'error_message' => $error_message, + 'images' => $listImg, )); ?> \ No newline at end of file diff --git a/vue/templates/profil.html.twig b/vue/templates/profil.html.twig index f6d4fa9..f32a82e 100644 --- a/vue/templates/profil.html.twig +++ b/vue/templates/profil.html.twig @@ -2,8 +2,26 @@

▶ Profil ◀

+

+ +

- + +

+

+ +
+ {% if images|length > 0 %} + {% for image in images %} +

+ +

+ {% endfor %} + {% else %} +

Aucune images n'a été trouvée.

+ {% endif %} +
+ {% if error_message is defined and error_message is not empty %}

{{ error_message }}

@@ -11,7 +29,9 @@

{{ srcUsername }}

-

{{ srcEmail }}

+

{{ srcEmail }} + +

Votre mot de passe