diff --git a/app/controllers/user_controller.php b/app/controllers/user_controller.php index f612a4a..ae38767 100644 --- a/app/controllers/user_controller.php +++ b/app/controllers/user_controller.php @@ -43,19 +43,105 @@ class UserCtrl{ include("../app/views/login.php"); include("../app/views/partials/footer.php"); - } + } public function logout(){ - session_start(); - - // on supprime l'utilisateur en session - unset($_SESSION['user']); - - $_SESSION['success'] = "Vous êtes bien déconnecté"; - - header("Location:index.php"); - exit; + 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; } - } \ No newline at end of file + + public function signin(){ + + // Inclusion du header + include("../app/views/partials/header.php"); + + // 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(); + $boolInsert = $objUserModel->insert($objUser); + + if ($boolInsert === true) { + $_SESSION['success'] = "Compte créé avec succès"; + header("Location:index.php?ctrl=user&action=login"); + exit; + } else { + // Erreur globale (pas liée à un champ) + $arrError['global'] = "Erreur lors de l'ajout"; + } + } + } + + // Affichage de la vue inscription + include("../app/views/inscription.php"); + include("../app/views/partials/footer.php"); + } + + + +} diff --git a/app/entity/user_entity.php b/app/entity/user_entity.php new file mode 100644 index 0000000..5e19525 --- /dev/null +++ b/app/entity/user_entity.php @@ -0,0 +1,124 @@ +_prefix = 'user_'; + } + + public function getId():int{ + return $this->_id; + } + public function setId(int $id){ + $this->_id = $id; + } + + public function getName():string{ + return $this->_name; + } + public function setName(string $name){ + $this->_name = $name; + } + + public function getFirstname():string{ + return $this->_firstname; + } + public function setFirstname(string $firstname){ + $this->_firstname = $firstname; + } + + public function getPseudo():string{ + return $this->_pseudo; + } + public function setPseudo(string $pseudo){ + $this->_pseudo = $pseudo; + } + + public function getImage():string{ + return $this->_image; + } + public function setImage(string $image){ + $this->_image = $image; + } + + public function getMail():string{ + return $this->_mail; + } + public function setMail(string $mail){ + $this->_mail = strtolower($mail); + } + + public function getPwd():string{ + return $this->_pwd; + } + public function getPwdHash():string{ + return password_hash($this->_pwd, PASSWORD_DEFAULT); + } + public function setPwd(string $pwd){ + $this->_pwd = $pwd; + } + + public function getPhone():string{ + return $this->_phone; + } + public function setPhone(string $phone){ + $this->_phone = $phone; + } + + public function getWork():string{ + return $this->_work; + } + public function setWork(string $work){ + $this->_work = $work; + } + + public function getBirth():string{ + return $this->_birth; + } + public function setBirth(string $birth){ + $this->_birth = $birth; + } + + public function getLocation():string{ + return $this->_location; + } + public function setLocation(string $location){ + $this->_location = $location; + } + + public function getDescription():string{ + return $this->_description; + } + public function setDescription(string $description){ + $this->_description = $description; + } + + public function getAccountCreation():string{ + return $this->_account_creation; + } + public function setAccountCreation(string $account_creation){ + $this->_account_creation = $account_creation; + } + + public function getStatus():int{ + return $this->_status; + } + public function setStatus(int $status){ + $this->_status = $status; + } + } diff --git a/app/models/user_model.php b/app/models/user_model.php index 73a5d34..706931b 100644 --- a/app/models/user_model.php +++ b/app/models/user_model.php @@ -3,7 +3,7 @@ /** * Traitement des requêtes pour les utilisateurs - * @author : Christel + * @author : meilleurGroup * @version : V0.5 */ class UserModel extends Connect{ @@ -58,17 +58,31 @@ public function insert(object $objUser):bool{ // 2. Construire la requête - $strRq = "INSERT INTO users (user_name, user_firstname, user_mail, user_pwd) - VALUES (:name, :firstname, :mail, :pwd)"; + /*$strRq = "INSERT INTO users (user_name, user_firstname, user_mail, user_pwd) + VALUES ('".$objUser->getName()."', + '".$objUser->getFirstname()."', + '".$objUser->getMail()."', + '".$objUser->getPwdHash()."')";*/ + $strRq = "INSERT INTO users (user_name, user_firstname, user_pseudo, user_mail, user_password, user_phone, user_work, user_location, user_description) + VALUES (:name, :firstname, :pseudo,:mail, :pwd, :phone, :work, :location,:description)"; // Préparer la requête $rqPrep = $this->_db->prepare($strRq); // Donne les informations $rqPrep->bindValue(":name", $objUser->getName(), PDO::PARAM_STR); $rqPrep->bindValue(":firstname", $objUser->getFirstname(), PDO::PARAM_STR); + $rqPrep->bindValue(":pseudo", $objUser->getPseudo(), PDO::PARAM_STR); $rqPrep->bindValue(":mail", $objUser->getMail(), PDO::PARAM_STR); $rqPrep->bindValue(":pwd", $objUser->getPwdHash(), PDO::PARAM_STR); + $rqPrep->bindValue(':phone', $objUser->getPhone() ?? "", PDO::PARAM_STR); + $rqPrep->bindValue(':work', $objUser->getWork() ?? "", PDO::PARAM_STR); + $rqPrep->bindValue(':location', $objUser->getLocation() ?? "", PDO::PARAM_STR); + $rqPrep->bindValue(':description', $objUser->getDescription() ?? "", PDO::PARAM_STR); + + // 3. Executer la requête + //var_dump($strRq);die; + //return $db->exec($strRq); return $rqPrep->execute(); } - } \ No newline at end of file + } diff --git a/app/views/connexion.php b/app/views/connexion.php index 96e2244..60c2e7b 100644 --- a/app/views/connexion.php +++ b/app/views/connexion.php @@ -1,4 +1,8 @@ + +
+ +
@@ -9,89 +13,92 @@
- -

Connexion

+

Connexion

- -

- Connectez-vous à votre compte. -

+

+ Connectez-vous à votre compte. +

- - -
- -
- - -
- - -
- - -
- - -
- - -
-
- - + + -
+ - -
- -
+ + - -
- - Pas encore de compte ? - Créer un compte - -
+
- - + +
+ + +
-
- + +
+ + +
+ + +
+
+ + +
+
+ + +
+ +
+ + +
+ + Pas encore de compte ? + Créer un compte + +
+ + + +
+
+
+
- - -
+ diff --git a/app/views/inscription.php b/app/views/inscription.php index efa1750..9595a92 100644 --- a/app/views/inscription.php +++ b/app/views/inscription.php @@ -1,4 +1,8 @@ + +
+ +
@@ -6,66 +10,193 @@
- +
- -

Inscription

+ +

Inscription

+

+ Créez votre compte utilisateur. +

- -

- Créez votre compte utilisateur. -

- - - -
- -
- - -
- - -
- - -
- - -
- - -
- -
- @ - + + + + + + + + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ +
+ @ + +
+
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + Déjà un compte ? + Se connecter + +
+ + +
+ +
+ +
+
@@ -183,6 +314,5 @@
-
- - +
+