diff --git a/controllers/user_controller.php b/controllers/user_controller.php index d981df7..9b8e5dd 100644 --- a/controllers/user_controller.php +++ b/controllers/user_controller.php @@ -7,63 +7,15 @@ require("./entities/project_entity.php"); class UserCtrl extends MotherCtrl { - - public function login(){ - - $strMail = $_POST['user_mail']??""; - $strPwd = $_POST['user_password']??""; - - // Tester le formulaire - $arrError = []; - if (count($_POST) > 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(){ + + /** + * Fonction d'inscription d'un utilisateur + * Effectue les validations du formulaire, + * vérifie l'unicité du mail et du pseudo, + * puis insère l'utilisateur en base de données + * @return void + */ + public function signup(){ // Entité pour réafficher les valeurs dans le formulaire $objUser = new User(); @@ -101,33 +53,40 @@ class UserCtrl extends MotherCtrl { } if (trim($objUser->getMail()) === "") { - $arrError['user_mail'] = "Le mail est obligatoire"; + $arrError['user_mail'] = "L'adresse e-mail est obligatoire"; } elseif (!filter_var($objUser->getMail(), FILTER_VALIDATE_EMAIL)) { - $arrError['user_mail'] = "Le format du mail n'est pas correct"; + $arrError['user_mail'] = "Le format de l'adresse e-mail est invalide"; } if (trim($objUser->getPseudo()) === "") { $arrError['user_pseudo'] = "Le pseudo est obligatoire"; } - $strRegex = "/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{16,}$/"; + $strRegex = "/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{15,}$/"; 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"; + $arrError['user_password'] = "Le mot de passe ne respecte pas les critères"; }else if($objUser->getPwd() != $strPwdConfirm){ - $arrError['pwd_confirm'] = "Le mot de passe et sa confirmation ne sont pas identiques"; + $arrError['pwd_confirm'] = "La confirmation du mot de passe ne correspond pas"; } - // Si pas d'erreurs => insertion if (count($arrError) === 0) { $objUserModel = new UserModel(); + // Vérif mail if ($objUserModel->mailExists($objUser->getMail())) { + $arrError['user_mail'] = "Impossible de créer le compte avec ces informations"; + } - $arrError['user_mail'] = "Ce mail existe déjà"; - } else { + // Vérif pseudo + if ($objUserModel->pseudoExists($objUser->getPseudo())) { + $arrError['user_pseudo'] = "Ce pseudo existe déjà"; + } + + // Si aucune erreur => insert + if (count($arrError) === 0) { $boolInsert = $objUserModel->insert($objUser); if ($boolInsert === true) { @@ -142,172 +101,236 @@ class UserCtrl extends MotherCtrl { } // 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; + $this->_arrData['objUser'] = $objUser; + $this->_arrData['arrError'] = $arrError; + $this->_display("signup"); } - - $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']); - - // Vérification de l'image - $arrTypeAllowed = array('image/jpeg', 'image/png', 'image/webp'); - $boolImageOk = true; - - if ($_FILES['image']['error'] != 4) { - if (!in_array($_FILES['image']['type'], $arrTypeAllowed)) { - $arrError['image'] = "Le type de fichier n'est pas autorisé"; - } else { - switch ($_FILES['image']['error']) { - case 0: - $strImageName = uniqid() . ".webp"; - $strOldImg = $objUser->getImage(); - $objUser->setImage($strImageName); - break; - case 1: - case 2: - $arrError['image'] = "Le fichier est trop volumineux"; - break; - case 3: - $arrError['image'] = "Le fichier a été partiellement téléchargé"; - break; - case 6: - $arrError['image'] = "Le répertoire temporaire est manquant"; - break; - default: - $arrError['image'] = "Erreur sur l'image"; - break; - } - } - } - - // Traitement de l'image si pas d'erreur - if (count($arrError) == 0 && isset($strImageName)) { - $strDest = $_ENV['IMG_USER_PATH'] . $strImageName; - $strSource = $_FILES['image']['tmp_name']; - list($intWidth, $intHeight) = getimagesize($strSource); - - $intDestWidth = 200; $intDestHeight = 200; - $fltDestRatio = $intDestWidth / $intDestHeight; - $fltSourceRatio = $intWidth / $intHeight; - - if ($fltSourceRatio > $fltDestRatio) { - $intCropHeight = $intHeight; - $intCropWidth = (int)round($intHeight * $fltDestRatio); - $intCropX = (int)(($intWidth - $intCropWidth) / 2); - $intCropY = 0; - } else { - $intCropWidth = $intWidth; - $intCropHeight = (int)round($intWidth / $fltDestRatio); - $intCropX = 0; - $intCropY = (int)(($intHeight - $intCropHeight) / 2); - } - - $objDest = imagecreatetruecolor($intDestWidth, $intDestHeight); - switch ($_FILES['image']['type']) { - case 'image/jpeg': $objSource = imagecreatefromjpeg($strSource); break; - case 'image/png': $objSource = imagecreatefrompng($strSource); break; - case 'image/webp': $objSource = imagecreatefromwebp($strSource); break; - } - - imagecopyresampled($objDest, $objSource, 0, 0, $intCropX, $intCropY, $intDestWidth, $intDestHeight, $intCropWidth, $intCropHeight); - $boolImageOk = imagewebp($objDest, $strDest); - imagedestroy($objDest); - imagedestroy($objSource); - } - - - $boolInsert = $objUserModel->update($objUser); - - if ($boolInsert === true) { - if (isset($strOldImg) && !empty($strOldImg) && isset($strImageName)) { - $strOldFile = $_ENV['IMG_USER_PATH'] . $strOldImg; - if (file_exists($strOldFile)) unlink($strOldFile); - } - $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"; - } - } + + /** + * Fonction de connexion d'un utilisateur + * Vérifie les informations envoyées par le formulaire + * et crée la session si les identifiants sont valides + * @return void + */ + public function login(){ + + $strMail = $_POST['user_mail']??""; + $strPwd = $_POST['user_password']??""; + + // Tester le formulaire + $arrError = []; + if (count($_POST) > 0) { + // Vérifier le formulaire + if ($strMail == ""){ + $arrError['mail'] = "L'adresse e-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[] = "Identifiants incorrects"; + }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; + + } + + + + /** + * 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"); } - $this->_arrData["arrError"] = $arrError; - $this->_arrData['objUser'] = $objUser; - $this->_display("useredit"); + 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']); + + // Vérification de l'image + $arrTypeAllowed = array('image/jpeg', 'image/png', 'image/webp'); + $boolImageOk = true; + + if ($_FILES['image']['error'] != 4) { + if (!in_array($_FILES['image']['type'], $arrTypeAllowed)) { + $arrError['image'] = "Le type de fichier n'est pas autorisé"; + } else { + switch ($_FILES['image']['error']) { + case 0: + $strImageName = uniqid() . ".webp"; + $strOldImg = $objUser->getImage(); + $objUser->setImage($strImageName); + break; + case 1: + case 2: + $arrError['image'] = "Le fichier est trop volumineux"; + break; + case 3: + $arrError['image'] = "Le fichier a été partiellement téléchargé"; + break; + case 6: + $arrError['image'] = "Le répertoire temporaire est manquant"; + break; + default: + $arrError['image'] = "Erreur sur l'image"; + break; + } + } + } + + // Traitement de l'image si pas d'erreur + if (count($arrError) == 0 && isset($strImageName)) { + $strDest = $_ENV['IMG_USER_PATH'] . $strImageName; + $strSource = $_FILES['image']['tmp_name']; + list($intWidth, $intHeight) = getimagesize($strSource); + + $intDestWidth = 200; $intDestHeight = 200; + $fltDestRatio = $intDestWidth / $intDestHeight; + $fltSourceRatio = $intWidth / $intHeight; + + if ($fltSourceRatio > $fltDestRatio) { + $intCropHeight = $intHeight; + $intCropWidth = (int)round($intHeight * $fltDestRatio); + $intCropX = (int)(($intWidth - $intCropWidth) / 2); + $intCropY = 0; + } else { + $intCropWidth = $intWidth; + $intCropHeight = (int)round($intWidth / $fltDestRatio); + $intCropX = 0; + $intCropY = (int)(($intHeight - $intCropHeight) / 2); + } + + $objDest = imagecreatetruecolor($intDestWidth, $intDestHeight); + switch ($_FILES['image']['type']) { + case 'image/jpeg': $objSource = imagecreatefromjpeg($strSource); break; + case 'image/png': $objSource = imagecreatefrompng($strSource); break; + case 'image/webp': $objSource = imagecreatefromwebp($strSource); break; + } + + imagecopyresampled($objDest, $objSource, 0, 0, $intCropX, $intCropY, $intDestWidth, $intDestHeight, $intCropWidth, $intCropHeight); + $boolImageOk = imagewebp($objDest, $strDest); + imagedestroy($objDest); + imagedestroy($objSource); + } + + + $boolInsert = $objUserModel->update($objUser); + + if ($boolInsert === true) { + if (isset($strOldImg) && !empty($strOldImg) && isset($strImageName)) { + $strOldFile = $_ENV['IMG_USER_PATH'] . $strOldImg; + if (file_exists($strOldFile)) unlink($strOldFile); + } + $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"); + + } + } diff --git a/views/_partial/footer.tpl b/views/_partial/footer.tpl index 9eaa238..bde1b20 100644 --- a/views/_partial/footer.tpl +++ b/views/_partial/footer.tpl @@ -5,7 +5,7 @@
  • Découvrir
  • Customisation
  • Emploi -
  • A propos +
  • A propos
    @@ -19,7 +19,7 @@
    @@ -31,4 +31,4 @@ - \ No newline at end of file + diff --git a/views/_partial/header.tpl b/views/_partial/header.tpl index 395bd39..06911af 100644 --- a/views/_partial/header.tpl +++ b/views/_partial/header.tpl @@ -7,7 +7,7 @@ - Folliow + Folliow{block name="title"}{/block}
    + -{/block} \ No newline at end of file +{/block} diff --git a/views/mentions.tpl b/views/mentions.tpl index 2aede88..9e23a03 100644 --- a/views/mentions.tpl +++ b/views/mentions.tpl @@ -1,287 +1,288 @@ -{extends file="views/layout.tpl"} - -{block name="title" append}Mentions légales{/block} -{block name="h2"}Mentions légales{/block} -{block name="p"}Informations légales et politique de confidentialité{/block} - -{block name="date_maj"} -

    - - Dernière mise à jour : -

    -{/block} - -{block name="js_footer" append} - -{/block} - -{block name="content"} -
    -

    Mentions légales

    - -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - -

    - Pour toute question concernant ces mentions légales ou pour exercer vos droits, vous pouvez nous contacter : -

    - -
    - -
    -
    -
    -{/block} \ No newline at end of file +{extends file="views/layout.tpl"} + +{block name="title" append} - Mentions légales{/block} + +{block name="h2"}Mentions légales{/block} +{block name="p"}Informations légales et politique de confidentialité{/block} + +{block name="date_maj"} +

    + + Dernière mise à jour : +

    +{/block} + +{block name="js_footer" append} + +{/block} + +{block name="content"} +
    +

    Mentions légales

    + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + +

    + Pour toute question concernant ces mentions légales ou pour exercer vos droits, vous pouvez nous contacter : +

    + +
    + +
    +
    +
    +{/block} diff --git a/views/project_display.tpl b/views/project_display.tpl index 7465d38..fb483e0 100644 --- a/views/project_display.tpl +++ b/views/project_display.tpl @@ -1,118 +1,96 @@ {extends file="views/layout.tpl"} +{block name="title" append} - Portfolio{/block} {block name="content"} -
    +
    - - {if isset($smarty.get.mail) && $smarty.get.mail === 'ok'} -
    Email envoyé avec succès.
    - {elseif isset($smarty.get.mail) && $smarty.get.mail === 'fail'} -
    Erreur lors de l'envoi de l'email.
    - {/if} + + {if isset($smarty.get.mail) && $smarty.get.mail === 'ok'} +
    Email envoyé avec succès.
    + {elseif isset($smarty.get.mail) && $smarty.get.mail === 'fail'} +
    Erreur lors de l'envoi de l'email.
    + {/if} -
    +
    - -
    + +
    -

    {$objProject->getTitle()}

    +

    {$objProject->getTitle()}

    -

    - {$arrProject.category_name ?? 'Général'} -

    +

    + {$arrProject.category_name ?? 'Général'} +

    -
    - -
    +
    + Aperçu du projet +
    -
    -

    Description

    -

    {$objProject->getDescription()}

    +
    +

    Description

    +

    {$objProject->getDescription()}

    -
    - {$objProject->getContent()} -
    -
    - - - -
    -

    Galerie du projet

    -
    - {foreach $arrImages as $image} - - {* On affiche l'image si elle est approuvée OU si l'utlilisateur possède le projet OU si l'utlilisateur est Modérateur*} - {if ($image.image_status == 'approuvé') || - (isset($smarty.session.user) && $smarty.session.user.user_status == 2) || - (isset($smarty.session.user) && $smarty.session.user.user_id == $objProject->getUser_id())} - -
    -
    - - {$image.image_alt} +
    + {$objProject->getContent()} +
    +
    - {* Visible uniquement par le modérateur *} - {if isset($smarty.session.user.user_status) && $smarty.session.user.user_status == 2} -
    -
    - Valider - - Supprimer -
    -
    - {/if} -
    -
    - {/if} - {foreachelse} -

    Aucune image disponible pour ce projet.

    - {/foreach} -
    - - - - -
    - + +
    + - + - + - + - -
    + +
    -
    +
    - -
    -
    - - - -
    {$objProject->getCreatorName()}
    + +
    -

    - Publié le {$objProject->getCreation_date()} -

    +
    + + Photo du créateur + - +
    {$objProject->getCreatorName()}
    -
    - {*Controle de l'utilisateur ainsi que du status du projet + Suppression disponible pour l'utilisateur possédant le projet*} +

    + Publié le {$objProject->getCreation_date()} +

    + + +
    + {*Controle de l'utilisateur ainsi que du status du projet + Suppression disponible pour l'utilisateur possédant le projet*} {if isset($smarty.session.user)} {if ($smarty.session.user.user_status == 2 || $smarty.session.user.user_id == $objProject->getUser_id())}
    diff --git a/views/search.tpl b/views/search.tpl index ea255b6..8f459c4 100644 --- a/views/search.tpl +++ b/views/search.tpl @@ -1,4 +1,5 @@ {extends file="views/layout.tpl"} +{block name="title" append} - Rechercher{/block} {block name="content"}
    @@ -186,4 +187,4 @@ // Initialisation au chargement toggleDateFields(); -{/block} \ No newline at end of file +{/block} diff --git a/views/signup.tpl b/views/signup.tpl new file mode 100644 index 0000000..21ec90a --- /dev/null +++ b/views/signup.tpl @@ -0,0 +1,202 @@ +{extends file="views/layout.tpl"} +{block name="title" append} - Inscription{/block} + +{block name="content"} + + +
    + + +
    +
    + + +
    + + +

    Inscription

    + + +

    + Créez votre compte utilisateur. +

    + + + +
    +
    + + +
    + + +
    + + +
    + + +
    + + +
    + +
    + @ + +
    +
    + + +
    + + +
    + + +
    + + +
    + + +
    + + +
    + + +
    + + +
    + + +
    + + +
    + + +
    + + +
    + + +
    + + +
    + + +
    + +
    + + +
    + + Déjà un compte ? + + Se connecter + + +
    + +
    +
    + +
    + +
    +
    + +
    +{/block} \ No newline at end of file