0) { // Vérifier le formulaire if ($strMail == ""){ $arrError['mail'] = "Le mail est obligatoire"; } if ($strPwd == ""){ $arrError['pwd'] = "Le mot de passe est obligatoire"; } // Si le formulaire est rempli correctement if (count($arrError) == 0){ // Vérifier l'utilisateur en BDD $objUserModel = new UserModel; $arrResult = $objUserModel->verifUser($strMail, $strPwd); //var_dump($arrResult); if ($arrResult === false){ // Si la base de données ne renvoie rien $arrError[] = "Mail ou mot de passe invalide"; }else{ // Ajoute l'utilisateur en session $_SESSION['user'] = $arrResult; $_SESSION['success'] = "Bienvenue, vous êtes bien connecté"; header("Location:index.php"); exit; } } } $this->_arrData['arrError'] = $arrError; $this->_display("login"); } public function logout(){ session_start(); /*session_destroy(); session_start();*/ // on supprime l'utilisateur en session unset($_SESSION['user']); $_SESSION['success'] = "Vous êtes bien déconnecté"; header("Location:index.php"); exit; } public function signin(){ // Entité pour réafficher les valeurs dans le formulaire $objUser = new User(); // Récupération des champs $strPwdConfirm = $_POST['pwd_confirm'] ?? ""; // Tableau d'erreurs $arrError = []; // Traitement du formulaire uniquement si POST if (!empty($_POST)) { // Hydratation $objUser->setName($_POST['user_name'] ?? ""); $objUser->setFirstname($_POST['user_firstname'] ?? ""); $objUser->setMail($_POST['user_mail'] ?? ""); $objUser->setPseudo($_POST['user_pseudo'] ?? ""); $objUser->setPwd($_POST['user_password'] ?? ""); // Champs optionnels : on les stocke aussi même si ils sont vides $objUser->setPhone($_POST['user_phone'] ?? ""); $objUser->setWork($_POST['user_work'] ?? ""); $objUser->setLocation($_POST['user_location'] ?? ""); $objUser->setDescription($_POST['user_description'] ?? ""); // --- VALIDATIONS (obligatoires) --- if (trim($objUser->getName()) === "") { $arrError['user_name'] = "Le nom est obligatoire"; } if (trim($objUser->getFirstname()) === "") { $arrError['user_firstname'] = "Le prénom est obligatoire"; } if (trim($objUser->getMail()) === "") { $arrError['user_mail'] = "Le mail est obligatoire"; } elseif (!filter_var($objUser->getMail(), FILTER_VALIDATE_EMAIL)) { $arrError['user_mail'] = "Le format du mail n'est pas correct"; } if (trim($objUser->getPseudo()) === "") { $arrError['user_pseudo'] = "Le pseudo est obligatoire"; } $strRegex = "/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{16,}$/"; if ($objUser->getPwd() == ""){ $arrError['user_password'] = "Le mot de passe est obligatoire"; }else if (!preg_match($strRegex, $objUser->getPwd())){ $arrError['user_password'] = "Le mot de passe ne correspond pas aux règles"; }else if($objUser->getPwd() != $strPwdConfirm){ $arrError['pwd_confirm'] = "Le mot de passe et sa confirmation ne sont pas identiques"; } // Si pas d'erreurs => insertion if (count($arrError) === 0) { $objUserModel = new UserModel(); if ($objUserModel->mailExists($objUser->getMail())) { $arrError['user_mail'] = "Ce mail existe déjà"; } else { $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"; } } } } // Affichage de la vue inscription $this->_arrData["arrError"] = $arrError; $this->_display("inscription"); } /** * le controlleur affichage de la page user */ public function user(){ /**$intId = isset($_GET['id']) ? (int)$_GET['id'] : 0; if ($intId <= 0) { header("Location: index.php"); exit; } //affichage info utilisateur $objUserModel = new UserModel; $arrUserData = $objUserModel->findUserById($intId); if ($arrUserData === false) { header("Location: index.php"); exit; }*/ $strPseudo = $_GET['pseudo']??''; $objUserModel = new UserModel; $arrUserData = $objUserModel->findUserByPseudo($strPseudo); if ($arrUserData === false) { header("Location: index.php"); exit; } $objUser = new User; $objUser->hydrate($arrUserData); //affichage projet de l'utilisateur $objProjectModel = new ProjectModel; $arrProjects = $objProjectModel->findAll(0,'',$objUser->getId()); $arrProjectToDisplay = array(); foreach($arrProjects as $projectData) { $objProject = new Project(); $objProject->hydrate($projectData); $arrProjectToDisplay[] = $objProject; } $this->_arrData['user'] = $objUser; $this->_arrData['arrProjectToDisplay'] = $arrProjectToDisplay; $this->_display("user"); } public function edit(){ if(!isset($_SESSION['user'])){ header("Location: index.php"); exit; } $objUserModel = new UserModel; $arrError = []; $objUser = new User; $arrUserData = $objUserModel->findUserById($_SESSION['user']['user_id']); $objUser->hydrate($arrUserData); if (!empty($_POST)) { if ($objUserModel->mailExists($_POST['user_mail']) && ($_POST['user_mail'] != $objUser->getMail())) { $arrError['user_mail'] = "Ce mail est déjà associé"; } else { if ($objUserModel->pseudoExists($_POST['user_pseudo']) && ($_POST['user_pseudo'] != $objUser->getPseudo())){ $arrError['user_pseudo'] = "Ce pseudo est déjà utiliser"; }else{ $objUser->hydrate($_POST); $objUser->setId($_SESSION['user']['user_id']); $boolInsert = $objUserModel->update($objUser); if ($boolInsert === true) { $arrNewInfo = $objUserModel->findUserByPseudo($objUser->getPseudo()); $_SESSION['user'] = $arrNewInfo; $_SESSION['success'] = "Compte modifier avec succès"; header("Location:?ctrl=user&action=user&pseudo=".$objUser->getPseudo()); exit; } else { $arrError['global'] = "Erreur lors de l'update"; } } } } $this->_arrData["arrError"] = $arrError; $this->_arrData['objUser'] = $objUser; $this->_display("useredit"); } }