Inscription
- - -- Créez votre compte utilisateur. -
- - - -diff --git a/composer.json b/composer.json index f2a1a02..60ba30e 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,8 @@ "name": "yasse/projetphp", "description": "le projet php de ces mort", "require": { - "smarty/smarty": "^5.7" + "smarty/smarty": "^5.7", + "phpmailer/phpmailer": "^7.0" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 57a15c5..5dad180 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,90 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "68f8d029d347b4c0c8cdbe33eeb96101", + "content-hash": "97f3233a5e69021ef84a92c5454bdb64", "packages": [ + { + "name": "phpmailer/phpmailer", + "version": "v7.0.2", + "source": { + "type": "git", + "url": "https://github.com/PHPMailer/PHPMailer.git", + "reference": "ebf1655bd5b99b3f97e1a3ec0a69e5f4cd7ea088" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/ebf1655bd5b99b3f97e1a3ec0a69e5f4cd7ea088", + "reference": "ebf1655bd5b99b3f97e1a3ec0a69e5f4cd7ea088", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-filter": "*", + "ext-hash": "*", + "php": ">=5.5.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "doctrine/annotations": "^1.2.6 || ^1.13.3", + "php-parallel-lint/php-console-highlighter": "^1.0.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcompatibility/php-compatibility": "^10.0.0@dev", + "squizlabs/php_codesniffer": "^3.13.5", + "yoast/phpunit-polyfills": "^1.0.4" + }, + "suggest": { + "decomplexity/SendOauth2": "Adapter for using XOAUTH2 authentication", + "directorytree/imapengine": "For uploading sent messages via IMAP, see gmail example", + "ext-imap": "Needed to support advanced email address parsing according to RFC822", + "ext-mbstring": "Needed to send email in multibyte encoding charset or decode encoded addresses", + "ext-openssl": "Needed for secure SMTP sending and DKIM signing", + "greew/oauth2-azure-provider": "Needed for Microsoft Azure XOAUTH2 authentication", + "hayageek/oauth2-yahoo": "Needed for Yahoo XOAUTH2 authentication", + "league/oauth2-google": "Needed for Google XOAUTH2 authentication", + "psr/log": "For optional PSR-3 debug logging", + "symfony/polyfill-mbstring": "To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)", + "thenetworg/oauth2-azure": "Needed for Microsoft XOAUTH2 authentication" + }, + "type": "library", + "autoload": { + "psr-4": { + "PHPMailer\\PHPMailer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1-only" + ], + "authors": [ + { + "name": "Marcus Bointon", + "email": "phpmailer@synchromedia.co.uk" + }, + { + "name": "Jim Jagielski", + "email": "jimjag@gmail.com" + }, + { + "name": "Andy Prevost", + "email": "codeworxtech@users.sourceforge.net" + }, + { + "name": "Brent R. Matzelle" + } + ], + "description": "PHPMailer is a full-featured email creation and transfer class for PHP", + "support": { + "issues": "https://github.com/PHPMailer/PHPMailer/issues", + "source": "https://github.com/PHPMailer/PHPMailer/tree/v7.0.2" + }, + "funding": [ + { + "url": "https://github.com/Synchro", + "type": "github" + } + ], + "time": "2026-01-09T18:02:33+00:00" + }, { "name": "smarty/smarty", "version": "v5.7.0", diff --git a/config/.gitkeep b/config/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/controllers/admin_controller.php b/controllers/admin_controller.php index dd4c1cf..63e92a1 100644 --- a/controllers/admin_controller.php +++ b/controllers/admin_controller.php @@ -18,8 +18,45 @@ class AdminCtrl extends MotherCtrl{ public function admin(){ + /*accès à la page admin + if (!isset($_SESSION['user']) && ($_SESSION['user']['user_status'] != 1 )){ + header("Location:index.php?ctrl=error&action=error_403"); + exit; + }*/ + $objCategoryModel = new CategoryModel; + + if (!empty($_POST['new_category'])) { + $objNewCategory = new Category; + if (!empty($objNewCategory->getName())) { + $objNewCategory = $_POST['new_category']; + $objCategoryModel->insertCategory($objNewCategory); + header("Location:index.php?ctrl=admin&action=admin"); + exit; + } + } + + if (!empty($_POST['edit_category'])) { + $objEditCategory = new Category; + if ($objEditCategory->getId() > 0) { + $objEditCategory = $_POST['edit_category']; + $objCategoryModel->editCategory($objEditCategory); + header("Location:index.php?ctrl=admin&action=admin"); + exit; + } + } + + $arrCategory = $objCategoryModel->findAllCategory(); + $arrCategoryToDisplay = array(); + + foreach($arrCategory as $arrDetCategory){ + $objCategory = new Category; + $objCategory->hydrate($arrDetCategory); + $arrCategoryToDisplay[] = $objCategory; + } - $this->_display("admin"); - + // Il faudra donner à maman et gérer l'affichage quand Smarty sera prêt + $this->_arrData['arrCategoryToDisplay'] = $arrCategoryToDisplay; + //$this->_arrData['intCategory'] = $objCategoryModel->; + $this->_display("admin"); } } diff --git a/controllers/mother_controller.php b/controllers/mother_controller.php index a5284f2..953a1ef 100644 --- a/controllers/mother_controller.php +++ b/controllers/mother_controller.php @@ -2,6 +2,7 @@ use Smarty\Smarty; + class MotherCtrl { protected array $_arrData = array(); // ou = [] diff --git a/controllers/project_controller.php b/controllers/project_controller.php index 216b1b9..af2e9fa 100644 --- a/controllers/project_controller.php +++ b/controllers/project_controller.php @@ -8,6 +8,9 @@ require("./models/user_model.php"); require("./entities/user_entity.php"); require("mother_controller.php"); + use PHPMailer\PHPMailer\PHPMailer; + use PHPMailer\PHPMailer\Exception; + use PHPMailer\PHPMailer\SMTP; /** * Le controler des Project @@ -50,25 +53,24 @@ $strStartDate = $_POST['startdate']??''; $strEndDate = $_POST['enddate']??''; $intCategory = $_POST['category']??0; - // Récupération des projetc + + // Récupération des projets $objProjectModel = new ProjectModel; $arrProject = $objProjectModel->findAll(intAuthor:$intAuthor, intPeriod:$intPeriod, strDate:$strDate, strKeywords:$strKeywords, strStartDate:$strStartDate, strEndDate:$strEndDate, intCategory:$intCategory); - - // Initialisation d'un tableau => objets $arrProjectToDisplay = array(); - // Boucle de transformation du tableau de tableau en tableau d'objets + foreach($arrProject as $arrDetProject){ $objProject = new Project; $objProject->hydrate($arrDetProject); - $arrProjectToDisplay[] = $objProject; } + // Récupération des utilisateurs $objUserModel = new UserModel; $arrUser = $objUserModel->findAllUsers(); - + // Récupération des catégories $objCategoryModel = new CategoryModel; $arrCategory = $objCategoryModel->findAllCategory(); @@ -159,9 +161,99 @@ } - public function admin(){ - - $this->_display("admin"); - - } + + public function display() { + $intId = $_GET['id'] ?? null; + + if ($intId) { + $objProjectModel = new ProjectModel(); + $arrProject = $objProjectModel->findOne((int)$intId); + + if ($arrProject) { + $objProject = new Project(); + $objProject->hydrate($arrProject); + + $this->_arrData["objProject"] = $objProject; + $this->_display("projet_display"); + } else { + header("Location: index.php?ctrl=project&action=home"); + exit; + } + } else { + header("Location: index.php?ctrl=project&action=home"); + exit; + } + } + + public function sendEmail() + { + if (count($_POST) > 0) { + + $projectId = (int)($_POST['project_id'] ?? 0); + $toEmail = trim($_POST['to_email'] ?? ''); + + if ($projectId <= 0 || !filter_var($toEmail, FILTER_VALIDATE_EMAIL)) { + header("Location: index.php?ctrl=project&action=display&id=".$projectId."&mail=fail"); + exit; + } + + $objProjectModel = new ProjectModel(); + $arrProject = $objProjectModel->findOne($projectId); + + if (!$arrProject) { + header("Location: index.php?ctrl=project&action=home"); + exit; + } + + $objProject = new Project(); + $objProject->hydrate($arrProject); + + + + $objMail = new PHPMailer(); // Nouvel objet Mail + $objMail->IsSMTP(); + $objMail->Mailer = "smtp"; + $objMail->CharSet = PHPMailer::CHARSET_UTF8; + + $objMail->SMTPDebug = 0; + + $objMail->SMTPAuth = TRUE; + $objMail->SMTPSecure = "tls"; + $objMail->Port = 587; + $objMail->Host = "smtp.gmail.com"; + $objMail->Username = "projet.folliow@gmail.com"; + $objMail->Password = "dqnw mqbu cwvg enbp"; + + $objMail->IsHTML(true); + + + $objMail->setFrom('projet.folliow@gmail.com', 'Projet Folliow'); + + + // Destinataire + $objMail->addAddress($toEmail); + + // Mail + $objMail->Subject = "Projet : " . $objProject->getTitle(); + + $url = "http://localhost/projet_php/public/index.php?ctrl=project&action=display&id=" . $projectId; + + $objMail->Body = + "
" . $objProject->getDescription() . "
" . + ""; + + // Envoi + redirection + if ($objMail->Send()) { + header("Location: index.php?ctrl=project&action=display&id=".$projectId."&mail=ok"); + } else { + // Pour debug si besoin: echo $objMail->ErrorInfo; exit; + header("Location: index.php?ctrl=project&action=display&id=".$projectId."&mail=fail"); + } + exit; + } + + header("Location: index.php?ctrl=project&action=home"); + exit; + } } \ No newline at end of file diff --git a/controllers/user_controller.php b/controllers/user_controller.php index 3a34aa7..70e2599 100644 --- a/controllers/user_controller.php +++ b/controllers/user_controller.php @@ -8,8 +8,8 @@ class UserCtrl extends MotherCtrl { public function login(){ - $strMail = $_POST['mail']??""; - $strPwd = $_POST['pwd']??""; + $strMail = $_POST['user_mail']??""; + $strPwd = $_POST['user_password']??""; // Tester le formulaire $arrError = []; @@ -127,13 +127,19 @@ class UserCtrl extends MotherCtrl { $objUserModel = new UserModel(); $boolInsert = $objUserModel->insert($objUser); - if ($boolInsert === true) { - $_SESSION['success'] = "Compte créé avec succès"; - header("Location:index.php?ctrl=user&action=login"); - exit; + if ($objUserModel->mailExists($objUser->getMail())) { + + $arrError['user_mail'] = "Ce mail existe déjà"; } else { - // Erreur globale (pas liée à un champ) - $arrError['global'] = "Erreur lors de l'ajout"; + $boolInsert = $objUserModel->insert($objUser); + + if ($boolInsert === true) { + $_SESSION['success'] = "Compte créé avec succès"; + header("Location:index.php?ctrl=user&action=login"); + exit; + } else { + $arrError['global'] = "Erreur lors de l'ajout"; + } } } } diff --git a/entities/category_entity.php b/entities/category_entity.php index 3b51e5b..c614541 100644 --- a/entities/category_entity.php +++ b/entities/category_entity.php @@ -9,11 +9,11 @@ require_once("mother_entity.php"); class Category extends Entity{ - private int $_id; - protected string $_name = ''; - protected string $_parent = ''; + private ?int $_id = null; + protected string $_name = ''; + protected ?int $_parent = null; - /** + /** * Constructeur (j'ai toujours pas compris à quoi ça sert) */ public function __construct(){ @@ -26,7 +26,7 @@ class Category extends Entity{ * Récuperation de l'id de la catégorie * @return int l'id de la catégorie */ - public function getId():int{ + public function getId(): ?int{ return $this->_id; } @@ -35,7 +35,11 @@ class Category extends Entity{ * @param int le nouvelle id */ public function setId($id){ - $this->_id = $id; + if (empty($id)) { + $this->_id = null; + } else { + $this->_id = (int) $id; + } } /** @@ -56,18 +60,22 @@ class Category extends Entity{ /** * Récuperation du nom du parent de la catégorie - * @return string nom de la catégorie + * @return int nom de la catégorie */ - public function getParent(){ + public function getParent():?int{ return $this->_parent; } /** * Mise à jour du nom du parent de la catégorie - * @param string le nouveau nom de la catégorie + * @param int le nouveau nom de la catégorie */ public function setParent($parent){ - $this->_parent = $parent; + if (empty($parent)) { + $this->_parent = null; + } else { + $this->_parent = (int) $parent; + } } } \ No newline at end of file diff --git a/index.php b/index.php index 8c958bd..f7890b4 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,5 @@ $strMethod(); + $objController->$strMethod (); }else{ $boolError = true; } diff --git a/models/category_model.php b/models/category_model.php index 0301c29..6432a9a 100644 --- a/models/category_model.php +++ b/models/category_model.php @@ -1,5 +1,5 @@ exec($strRq); return $rqPrep->execute(); } + + public function findOne(int $intId) { + $strRq = "SELECT project.*, + CONCAT(users.user_firstname, ' ', users.user_name) AS 'project_creatorname', + users.user_image, + category.category_name + FROM project + INNER JOIN users ON users.user_id = project.project_user + LEFT JOIN category ON category.category_id = project.project_category + WHERE project.project_id = :id"; + + $rqPrep = $this->_db->prepare($strRq); + $rqPrep->bindValue(":id", $intId, PDO::PARAM_INT); + $rqPrep->execute(); + + return $rqPrep->fetch(); + } } \ No newline at end of file diff --git a/models/user_model.php b/models/user_model.php index 83debc8..72f1ada 100644 --- a/models/user_model.php +++ b/models/user_model.php @@ -1,5 +1,6 @@ _db->query($strRq)->fetchAll(); } @@ -33,8 +34,8 @@ */ public function verifUser(string $strMail, string $strPwd):array|bool{ // 2. Construire la requête - $strRq = "SELECT user_id, user_name, user_firstname, user_password, user_image - FROM users + $strRq = "SELECT user_id, user_name, user_firstname, user_password, user_image, user_status, authorisation_name + FROM users INNER JOIN authorisation ON authorisation.authorisation_id = users.user_status WHERE user_mail = '".$strMail."'"; // Récupère mon utilisateur // Executer la requête et récupérer les résultats @@ -81,4 +82,12 @@ //return $db->exec($strRq); return $rqPrep->execute(); } + public function mailExists(string $mail): bool + { + $rq = $this->_db->prepare("SELECT 1 FROM users WHERE user_mail = :mail LIMIT 1"); + $rq->bindValue(":mail", $mail); + $rq->execute(); + + return (bool)$rq->fetchColumn(); + } } diff --git a/templates_c/0f54e8b5c9bcafd01d94486bfa02ee91c2c5fe68_0.file_home.tpl.php b/templates_c/0f54e8b5c9bcafd01d94486bfa02ee91c2c5fe68_0.file_home.tpl.php index 720dec7..76d88b5 100644 --- a/templates_c/0f54e8b5c9bcafd01d94486bfa02ee91c2c5fe68_0.file_home.tpl.php +++ b/templates_c/0f54e8b5c9bcafd01d94486bfa02ee91c2c5fe68_0.file_home.tpl.php @@ -1,11 +1,11 @@ getCompiled()->isFresh($_smarty_tpl, array ( 'version' => '5.7.0', - 'unifunc' => 'content_6988e6e030cfc2_17810205', + 'unifunc' => 'content_6989b403135214_06797903', 'has_nocache_code' => false, 'file_dependency' => array ( @@ -21,20 +21,20 @@ if ($_smarty_tpl->getCompiled()->isFresh($_smarty_tpl, array ( 'file:views/_partial/preview.tpl' => 1, ), ))) { -function content_6988e6e030cfc2_17810205 (\Smarty\Template $_smarty_tpl) { +function content_6989b403135214_06797903 (\Smarty\Template $_smarty_tpl) { $_smarty_current_dir = 'D:\\projetphp\\views'; $_smarty_tpl->getInheritance()->init($_smarty_tpl, true); ?> getInheritance()->instanceBlock($_smarty_tpl, 'Block_14883993436988e6e03087b1_93283416', "content"); +$_smarty_tpl->getInheritance()->instanceBlock($_smarty_tpl, 'Block_8519413186989b403131000_39935260', "content"); ?> getInheritance()->endChild($_smarty_tpl, "views/layout.tpl", $_smarty_current_dir); } /* {block "content"} */ -class Block_14883993436988e6e03087b1_93283416 extends \Smarty\Runtime\Block +class Block_8519413186989b403131000_39935260 extends \Smarty\Runtime\Block { public function callBlock(\Smarty\Template $_smarty_tpl) { $_smarty_current_dir = 'D:\\projetphp\\views'; diff --git a/templates_c/184f81453f2b8e9c87b8f61bf5df178eaf9a1be4_0.file_inscription.tpl.php b/templates_c/184f81453f2b8e9c87b8f61bf5df178eaf9a1be4_0.file_inscription.tpl.php deleted file mode 100644 index 67893a4..0000000 --- a/templates_c/184f81453f2b8e9c87b8f61bf5df178eaf9a1be4_0.file_inscription.tpl.php +++ /dev/null @@ -1,218 +0,0 @@ -getCompiled()->isFresh($_smarty_tpl, array ( - 'version' => '5.7.0', - 'unifunc' => 'content_6988e6eb196d91_26203411', - 'has_nocache_code' => false, - 'file_dependency' => - array ( - '184f81453f2b8e9c87b8f61bf5df178eaf9a1be4' => - array ( - 0 => 'views/inscription.tpl', - 1 => 1770579251, - 2 => 'file', - ), - ), - 'includes' => - array ( - ), -))) { -function content_6988e6eb196d91_26203411 (\Smarty\Template $_smarty_tpl) { -$_smarty_current_dir = 'D:\\projetphp\\views'; -$_smarty_tpl->getInheritance()->init($_smarty_tpl, true); -?> - - -getInheritance()->instanceBlock($_smarty_tpl, 'Block_10194680646988e6eb195117_68573569', "content"); -$_smarty_tpl->getInheritance()->endChild($_smarty_tpl, "views/layout.tpl", $_smarty_current_dir); -} -/* {block "content"} */ -class Block_10194680646988e6eb195117_68573569 extends \Smarty\Runtime\Block -{ -public function callBlock(\Smarty\Template $_smarty_tpl) { -$_smarty_current_dir = 'D:\\projetphp\\views'; -?> - - - - -- Créez votre compte utilisateur. -
- - - -