selection image profil

pull/24/head
brongniart 3 months ago
commit 35b5543061

@ -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';

@ -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');

@ -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);
}

@ -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;

@ -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);
}

@ -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. Cest 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);
}
}

@ -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;
}
}

@ -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
";

@ -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();
}
}
?>

@ -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
{

@ -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;
}

@ -17,5 +17,6 @@
'srcEmail' => $p->getEmail(),
'srcImg' => $p->getImgPrfl(),
'error_message' => $error_message,
'images' => $listImg,
));
?>

@ -2,8 +2,26 @@
<div class="login">
<h1>▶ Profil ◀</h1>
<p name="image" id="image">
<button popovertarget="list-ChangeImg" name="image" class="ChangeImg"><img src="{{ srcImg }}" class="imageProfil"/></button>
</p>
<form method="post" action="{{ racine }}/changedata">
<button name="image" class="ChangeImg" value="1" type="Submit"><img src="{{ srcImg }}" class="imageProfil" onmousedown="return false"/></button>
<p name="imagePost" id="imagePost">
</p>
<div popover id="list-ChangeImg" >
{% if images|length > 0 %}
{% for image in images %}
<p class="ChangeImg" onclick="editFieldImage({{ image.idImg }},'{{ image.imgPath }}')">
<img src="{{ image.imgPath }}" class="imageProfil" />
</p>
{% endfor %}
{% else %}
<p>Aucune images n'a été trouvée.</p>
{% endif %}
</div>
{% if error_message is defined and error_message is not empty %}
<p style="color: red">{{ error_message }}</p>
@ -11,7 +29,9 @@
<p class="infoProfil" name="pseudo" id="username"> <strong>{{ srcUsername }}</strong><img class='imgModify' src='{{ racine }}/images/modify.svg' onclick="editFieldUsername('username')"/></p>
<p class="infoProfil" name="email" id="email"> <strong> {{ srcEmail }}</strong><img class='imgModify' src='{{ racine }}/images/modify.svg' onclick="editFieldEmail('email')"/></p>
<p class="infoProfil" name="email" id="email"> <strong> {{ srcEmail }}</strong>
<img class='imgModify' src='{{ racine }}/images/modify.svg' onclick="editFieldEmail('email')"/>
</p>
<p class="infoProfil" name="mdp" id="passwd"> <strong>Votre mot de passe</strong><img class='imgModify' src='{{ racine }}/images/modify.svg' onclick="editFieldPassWd('passwd')"/></p>

Loading…
Cancel
Save