diff --git a/config/config.php b/config/config.php index 4ba3eaf..18ac15c 100644 --- a/config/config.php +++ b/config/config.php @@ -12,7 +12,11 @@ $base = ''; $login = ''; $mdp = ''; -$racine='~kekentin/WF/WF-Website'; // /~kekentin/WF/WF-Website + + +$racine='/~kekentin/WF/WF-Website'; // /~kekentin/WF/WF-Website /~lebeaulato/WF-Website /~kemondejar/WF-Website +//$racine='/WF-Website'; + diff --git a/index.php b/index.php index 2de51d3..3bc9649 100644 --- a/index.php +++ b/index.php @@ -15,8 +15,8 @@ if(!isset($_SESSION['theme'])){ require_once __DIR__ . '/config/config.php'; require __DIR__ . '/vendor/autoload.php'; -$co = new \Gateway\Connection('pgsql:host=localhost;dbname=wikifantasy3;', 'postgres', 'postgres'); -//$co = new \Gateway\Connection('pgsql:host=localhost;dbname=dbkekentin;', 'kekentin', 'passwd'); +//$co = new \Gateway\Connection('pgsql:host=localhost;dbname=wikifantasy3;', 'postgres', 'postgres'); +$co = new \Gateway\Connection('pgsql:host=localhost;dbname=dbkekentin;', 'kekentin', 'passwd'); //twig $loader = new \Twig\Loader\FilesystemLoader('vue/templates'); 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 fc5a0f7..ba13c83 100644 --- a/src/Controleur/UserControler.php +++ b/src/Controleur/UserControler.php @@ -21,6 +21,8 @@ use Twig\Error\RuntimeError; use Twig\Error\SyntaxError; use Verification\Verification; use Enum\TypeSourceEnum; +use Model\ImageModel; +use Gateway\ImageGateway; class UserControler { @@ -30,6 +32,7 @@ class UserControler { private QuestionModel $mdl; private CharacterModel $caMod; private SourceModel $srcMod; + private ImageModel $iMod; public function __construct() { global $co; @@ -39,12 +42,14 @@ class UserControler { $this -> mdl = new QuestionModel(new QuestionGateway($co)); $this -> caMod = new CharacterModel(new CharacterGateway($co)); $this->srcMod = new SourceModel(new SourceGateway($co)); + $this->iMod = new ImageModel(new ImageGateway($co)); } public function profil() { global $vues; $p = $this->uMod->getUsername($_SESSION["user"]); + $listImg = $this->iMod->getAllImg() ; // Pour les messages d'erreur $error_message = null; @@ -243,7 +248,7 @@ class UserControler { $this->updatePassWd($oldPasswd, $newMdpFirst,$newMdpSecond); } else if($newImage){//Modif l'image - $this->updateImg(); + $this->updateImg($newImage); } } header("Location: ". $racine."/profil"); @@ -300,8 +305,8 @@ class UserControler { } } - public function updateImg(){ - $user = $this->uMod->setImage($_SESSION['user']); + public function updateImg(string $newImage){ + $user = $this->uMod->setImage($_SESSION['user'],$newImage); } diff --git a/src/Controleur/VisitorControler.php b/src/Controleur/VisitorControler.php index 99589af..0b57488 100644 --- a/src/Controleur/VisitorControler.php +++ b/src/Controleur/VisitorControler.php @@ -131,6 +131,7 @@ 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 @@ -195,6 +196,7 @@ Class VisitorControler { exit(); } else echo $this->uMod->insertUser($pseudo, $email, $hmdp); + $this->sendEmailSignin($pseudo,$email); $_SESSION["role"] = Verification::verifChar('user'); $_SESSION["user"] = Verification::verifChar($pseudo); @@ -202,4 +204,38 @@ Class VisitorControler { header("Location: ". $racine); } } + + 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, + + 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 + "; // Contenu de l'email + $headers = "From: noreply@whatTheFantasy.com"; // Adresse email de l'expéditeur + + // 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, + + 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. + + + 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); + } } \ No newline at end of file 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/Gateway/ImageGateway.php b/src/Gateway/ImageGateway.php index e05609a..b001554 100644 --- a/src/Gateway/ImageGateway.php +++ b/src/Gateway/ImageGateway.php @@ -6,25 +6,24 @@ 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 Images - VALUES (:id_img, :img_path, :is_img_profile) + INSERT INTO Image + VALUES (:id_img, :img_path) "; return $this -> co -> executeQuery($query, [ 'id_img' => array($idImg, PDO::PARAM_INT), 'img_path' => array($imgPath, PDO::PARAM_STR), - 'is_img_profile' => array($isImgProfile, PDO::PARAM_BOOL), ]); } 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)]); @@ -35,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); @@ -58,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)]); @@ -68,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 cee829e..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))); @@ -200,5 +210,11 @@ Class UserGateway extends Gateway{ $query = 'UPDATE Users SET password=:newPassWd WHERE username=:username'; $this->co->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR), ':newPassWd'=> array($newPassWd, PDO::PARAM_STR))); } + + public function emailWithUser(string $user):array{ + $query = 'SELECT email FROM Users WHERE username = :user'; + $this->co->executeQuery($query, array(':user'=>array($user, PDO::PARAM_STR))); + return $this->co->getResults(); + } } ?> diff --git a/src/Model/ImageModel.php b/src/Model/ImageModel.php index e9ac02b..9192ecc 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 getImgById(int $idImg) : ?ImageEntity @@ -20,9 +20,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; @@ -37,30 +36,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 28f0c23..5dd1edc 100644 --- a/src/Model/UserModel.php +++ b/src/Model/UserModel.php @@ -85,6 +85,11 @@ return $res[0]['id_user']; } + public function getEmailWithUser(string $user){ + $res = $this->gateway->emailWithUser($user); + return $res[0]['email']; + } + // ===================== Bool FUNCTION ===================== public function IsExisteUsername(string $username):bool{ @@ -145,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 ae4a1ee..a8b1b4d 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