From d7468fc363b5d028db84373d4abfa6d7d19bacb9 Mon Sep 17 00:00:00 2001 From: polo Date: Mon, 11 Aug 2025 06:25:39 +0200 Subject: =?UTF-8?q?nouveau=20routeur!=20et=20contr=C3=B4leurs=20et=20vues?= =?UTF-8?q?=20pour=20la=20connexion=20et=20la=20gestion=20du=20compte,=20d?= =?UTF-8?q?=C3=A9but=20d'utilisation=20de=20Request=20et=20Response?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Security.php | 11 +- src/controller/ArticleController.php | 4 +- src/controller/UserController.php | 360 +++++++++++++++++++++++++++++++++++ src/controller/ViewController.php | 39 ++++ src/controller/password.php | 328 ------------------------------- src/installation.php | 12 +- src/model/entities/Image.php | 2 +- src/model/entities/User.php | 5 +- src/request_router.php | 256 ------------------------- src/router.php | 302 +++++++++++++++++++++++++++++ src/view/FooterBuilder.php | 8 +- src/view/LoginBuilder.php | 41 +++- src/view/MainBuilder.php | 2 +- src/view/UserEditBuilder.php | 58 ++++++ src/view/ViewBuilder.php | 18 -- src/view/password.php | 155 --------------- src/view/templates/login.php | 28 +++ src/view/templates/user_create.php | 52 +++++ src/view/templates/user_edit.php | 62 ++++++ 19 files changed, 963 insertions(+), 780 deletions(-) create mode 100644 src/controller/UserController.php create mode 100644 src/controller/ViewController.php delete mode 100644 src/controller/password.php delete mode 100644 src/request_router.php create mode 100644 src/router.php create mode 100644 src/view/UserEditBuilder.php delete mode 100644 src/view/ViewBuilder.php delete mode 100644 src/view/password.php create mode 100644 src/view/templates/login.php create mode 100644 src/view/templates/user_create.php create mode 100644 src/view/templates/user_edit.php (limited to 'src') diff --git a/src/Security.php b/src/Security.php index b2042fd..c825994 100644 --- a/src/Security.php +++ b/src/Security.php @@ -19,8 +19,8 @@ class Security // faire qu'un certain élément puisse n'avoir que certains attributs, regarder la doc private static $specHtmLawed = ''; - // ATTENTION, n'applique pas htmlspecialchars() !! - public static function secureString(string $chaine): string + // obtenir du HTML non dangereur sans appliquer htmlspecialchars + public static function secureHTML(string $chaine): string { return trim(htmLawed($chaine, self::$configHtmLawed, self::$specHtmLawed)); } @@ -80,13 +80,6 @@ class Security } } -// erreurs à la création des mots de passe -function removeSpacesTabsCRLF(string $chaine): string -{ - $cibles = [' ', "\t", "\n", "\r"]; // doubles quotes !! - return(str_replace($cibles, '', $chaine)); -} - // lien sans http:// function fixLinks($data) { diff --git a/src/controller/ArticleController.php b/src/controller/ArticleController.php index e3e4edb..3b39335 100644 --- a/src/controller/ArticleController.php +++ b/src/controller/ArticleController.php @@ -19,12 +19,12 @@ class ArticleController // cas d'une nouvelle "news" if(is_array($json['content'])){ foreach($json['content'] as $one_input){ - $one_input = Security::secureString($one_input); + $one_input = Security::secureHTML($one_input); } $content = $json['content']; } else{ - $content = Security::secureString($json['content']); + $content = Security::secureHTML($json['content']); } // nouvel article diff --git a/src/controller/UserController.php b/src/controller/UserController.php new file mode 100644 index 0000000..50e8bf7 --- /dev/null +++ b/src/controller/UserController.php @@ -0,0 +1,360 @@ +getRepository(User::class)->findAll(); + + if(count($users) === 0) // table vide + { + $_SESSION['user'] = ''; + $_SESSION['admin'] = false; + + return false; + } + else{ + return true; + } + } + + static public function createUser(EntityManager $entityManager) + { + // test mauvais paramètres + if(!isset($_POST['login']) || empty($_POST['login']) + || !isset($_POST['password']) || empty($_POST['password']) + || !isset($_POST['password_confirmation']) || empty($_POST['password_confirmation']) + || !isset($_POST['create_user_hidden']) || !empty($_POST['create_user_hidden'])) + { + header('Location: ' . new URL); + die; + } + + unset($_SESSION['user']); + + $captcha_solution = (isset($_SESSION['captcha']) && is_int($_SESSION['captcha'])) ? $_SESSION['captcha'] : 0; + $captcha_try = isset($_POST['captcha']) ? Captcha::controlInput($_POST['captcha']) : 0; + unset($_SESSION['captcha']); + + $error = ''; + if($captcha_try == 0) + { + $error = 'error_non_valid_captcha'; + } + elseif($captcha_solution == 0) // ne peut pas arriver, si? + { + $error = 'captcha_server_error'; + } + elseif($captcha_try != $captcha_solution) // le test! + { + $error = 'bad_solution_captcha'; + } + elseif($_POST['password'] !== $_POST['password_confirmation']) + { + $error = 'different_passwords'; + } + else + { + $login = self::removeSpacesTabsCRLF(htmlspecialchars($_POST['login'])); + $password = self::removeSpacesTabsCRLF(htmlspecialchars($_POST['password'])); + + // self::removeSpacesTabsCRLF prévient la validation par erreur d'une chaine "vide" + + // conformité + if(!empty($password) && !empty($login) + && $password === $_POST['password'] && $login === $_POST['login']) + { + // enregistrement et redirection + $password = password_hash($password, PASSWORD_DEFAULT); + $user = new App\Entity\User($login, $password); + $entityManager->persist($user); + $entityManager->flush(); + + header('Location: ' . new URL); + die; + } + else{ + $error = 'forbidden_characters'; + } + } + + $url = empty($error) ? new URL : new URL(['error' => $error]); + header('Location: ' . $url); + die; + } + + static public function connect(EntityManager $entityManager): void + { + if($_SESSION['admin']) // déjà connecté? + { + header('Location: ' . new URL); + die; + } + + $_SESSION['user'] = ''; + $_SESSION['admin'] = false; + + $captcha_solution = (isset($_SESSION['captcha']) && is_int($_SESSION['captcha'])) ? $_SESSION['captcha'] : 0; + $captcha_try = isset($_POST['captcha']) ? Captcha::controlInput($_POST['captcha']) : 0; + unset($_SESSION['captcha']); + + $error = ''; + if($captcha_try == 0) + { + $error = 'error_non_valid_captcha'; + } + elseif($captcha_solution == 0) // pas censé se produire + { + $error = 'captcha_server_error'; + } + elseif($captcha_try != $captcha_solution) // le test! + { + $error = 'bad_solution_captcha'; + } + elseif(!isset($_POST['login']) || empty($_POST['login']) + || !isset($_POST['password']) || empty($_POST['password'])) + { + $error = 'bad_login_or_password'; + } + else // c'est OK + { + $login = trim($_POST['login']); + $password = trim($_POST['password']); + $user = self::getUser($login, $entityManager); + + // enregistrement et redirection + if(!empty($user) && $login === $user->getLogin() && password_verify($password, $user->getPassword())) + { + $log = new Log(true); + $entityManager->persist($log); + $entityManager->flush(); + + // protection fixation de session, si l'attaquant crée un cookie de session, il est remplacé + session_regenerate_id(true); + + $_SESSION['user'] = $login; + $_SESSION['admin'] = true; + + $url = new URL(isset($_GET['from']) ? ['page' => $_GET['from']] : []); + isset($_GET['id']) ? $url->addParams(['id' => $_GET['id']]) : ''; + header('Location: ' . $url); + die; + } + else + { + $log = new Log(false); + $entityManager->persist($log); + $entityManager->flush(); + $error = 'bad_login_or_password'; + } + } + + // tous les cas sauf connexion réussie + sleep(1); // défense basique à la force brute + $url = new URL(isset($_GET['from']) ? ['page' => 'connexion', 'from' => $_GET['from']] : []); + isset($_GET['id']) ? $url->addParams(['id' => $_GET['id']]) : ''; + !empty($error) ? $url->addParams(['error' => $error]) : ''; + header('Location: ' . $url); + die; + } + + static public function disconnect(): void + { + // nettoyage complet + $_SESSION = []; // mémoire vive + session_destroy(); // fichier côté serveur + setcookie('PHPSESSID', '', time() - 86400, '/'); // cookie de session + + // retour même page + $url = new URL; + isset($_GET['from']) ? $url->addParams(['page' => $_GET['from']]) : ''; + isset($_GET['id']) ? $url->addParams(['id' => $_GET['id']]) : ''; + header('Location: ' . $url); + die; + } + + static public function updateUsername(EntityManager $entityManager): void + { + if(!$_SESSION['admin']) // superflux, fait dans le routeur + { + self::disconnect(); + } + + $captcha_solution = (isset($_SESSION['captcha']) && is_int($_SESSION['captcha'])) ? $_SESSION['captcha'] : 0; + $captcha_try = isset($_POST['captcha']) ? Captcha::controlInput($_POST['captcha']) : 0; + unset($_SESSION['captcha']); + + $url = new URL(['page' => 'user_edit']); + isset($_GET['from']) ? $url->addParams(['from' => $_GET['from']]) : null; + + $error = ''; + if(!isset($_POST['old_login']) || empty($_POST['old_login']) + || !isset($_POST['password']) || empty($_POST['password']) + || !isset($_POST['new_login']) || empty($_POST['new_login']) + || !isset($_POST['modify_username_hidden']) || !empty($_POST['modify_username_hidden'])) + { + $error = 'bad_login_or_password'; + } + elseif($captcha_try != $captcha_solution) // le test! + { + $error = 'bad_solution_captcha'; + } + else + { + // sécurisation de la saisie + $old_login = $_POST['old_login']; + $password = $_POST['password']; + $new_login = self::removeSpacesTabsCRLF(htmlspecialchars($_POST['new_login'])); + // removeSpacesTabsCRLF pour éviter d'enregistrer une chaîne vide + + // tests de conformité + if($old_login !== $_POST['old_login'] || $password !== $_POST['password'] || $new_login !== $_POST['new_login']) + { + $error = 'forbidden_characters'; + } + elseif($old_login !== $_SESSION['user']){ + $error = 'bad_login_or_password'; + } + elseif($old_login === $new_login){ + $error = 'same_username_as_before'; + } + else + { + $user = self::getUser($old_login, $entityManager); + + if(password_verify($password, $user->getPassword())) + { + $user->setLogin($new_login); + $entityManager->flush(); + $_SESSION['user'] = $new_login; + + $url->addParams(['success_login' => 'new_login']); + $error = ''; + } + else + { + $error = 'bad_login_or_password'; + } + } + } + + if(!empty($error)){ + sleep(1); + $url->addParams(['error_login' => $error]); + } + + header('Location: ' . $url); + die; + } + + static public function updatePassword(EntityManager $entityManager): void + { + if(!$_SESSION['admin']) // superflux, fait dans le routeur + { + self::disconnect(); + } + + $captcha_solution = (isset($_SESSION['captcha']) && is_int($_SESSION['captcha'])) ? $_SESSION['captcha'] : 0; + $captcha_try = isset($_POST['captcha']) ? Captcha::controlInput($_POST['captcha']) : 0; + unset($_SESSION['captcha']); + + $url = new URL(['page' => 'user_edit']); + isset($_GET['from']) ? $url->addParams(['from' => $_GET['from']]) : null; + + $error = ''; + if(!isset($_POST['login']) || empty($_POST['login']) + || !isset($_POST['old_password']) || empty($_POST['old_password']) + || !isset($_POST['new_password']) || empty($_POST['new_password']) + || !isset($_POST['modify_password_hidden']) || !empty($_POST['modify_password_hidden'])) + { + $error = 'bad_login_or_password'; + } + elseif($captcha_try != $captcha_solution) // le test! + { + $error = 'bad_solution_captcha'; + } + else + { + // sécurisation de la saisie + $login = $_POST['login']; + $old_password = $_POST['old_password']; + $new_password = self::removeSpacesTabsCRLF(htmlspecialchars($_POST['new_password'])); + // removeSpacesTabsCRLF pour éviter d'enregistrer une chaîne vide + + // tests de conformité + if($login !== $_POST['login'] || $old_password !== $_POST['old_password'] || $new_password !== $_POST['new_password']) + { + $error = 'forbidden_characters'; + } + elseif($login !== $_SESSION['user']){ + $error = 'bad_login_or_password'; + } + elseif($old_password === $new_password){ + $error = 'same_password_as_before'; + } + else + { + $user = self::getUser($login, $entityManager); + + if(password_verify($old_password, $user->getPassword())) + { + $new_password = password_hash($new_password, PASSWORD_DEFAULT); + $user->setPassword($new_password); + $entityManager->flush(); + + $url->addParams(['success_password' => 'new_password']); + $error = ''; + } + else + { + $error = 'bad_login_or_password'; + } + } + } + + if(!empty($error)){ + sleep(1); + $url->addParams(['error_password' => $error]); + } + + header('Location: ' . $url); + die; + } + + static private function getUser(string $login, EntityManager $entityManager): ?User + { + $users = $entityManager->getRepository('App\Entity\User')->findBy(['login' => $login]); + + if(count($users) === 0) + { + $_SESSION['user'] = ''; + $_SESSION['admin'] = false; + } + + foreach($users as $user) + { + if($user->getLogin() === $login) + { + return $user; + } + } + return null; + } + + // erreurs à la création des mots de passe + static private function removeSpacesTabsCRLF(string $chaine): string + { + $cibles = [' ', "\t", "\n", "\r"]; // doubles quotes !! + return(str_replace($cibles, '', $chaine)); + } +} \ No newline at end of file diff --git a/src/controller/ViewController.php b/src/controller/ViewController.php new file mode 100644 index 0000000..69955c6 --- /dev/null +++ b/src/controller/ViewController.php @@ -0,0 +1,39 @@ +makeRootNode(htmlspecialchars($request->query->get('id') ?? '')); + self::$root_node = $director->getNode(); + + // mode modification d'une page activé + if($_SESSION['admin'] && $request->query->has('page') + && $request->query->has('action') && $request->query->get('action') === 'modif_page' + && $request->query->get('page') !== 'connexion' && $request->query->get('page') !== 'article' && $request->query->get('page') !== 'nouvelle_page' && $request->query->get('page') !== 'menu_chemins'){ + // les contrôles de la 2è ligne devraient utiliser un tableau + MainBuilder::$modif_mode = true; + } + + // construction de la page + $this->useChildrenBuilder(self::$root_node); + + return new Response($this->html, 200); + } +} \ No newline at end of file diff --git a/src/controller/password.php b/src/controller/password.php deleted file mode 100644 index 3d003da..0000000 --- a/src/controller/password.php +++ /dev/null @@ -1,328 +0,0 @@ -getRepository(User::class)->findAll(); - - // cas particulier table vide - if(count($users) === 0) - { - $_GET = []; - $_SESSION['user'] = ''; - $_SESSION['admin'] = false; - - // création d'un utilisateur, puis rechargement de la page - createPassword($entityManager); - } -} - - -function createPassword(EntityManager $entityManager) -{ - // fonction exécutée à priori deux fois d'affilée: affichage puis traitement de la saisie - - unset($_SESSION['user']); - - $captcha_solution = (isset($_SESSION['captcha']) && is_int($_SESSION['captcha'])) ? $_SESSION['captcha'] : 0; - $captcha_try = isset($_POST['captcha']) ? Captcha::controlInput($_POST['captcha']) : 0; - - // II - traitement - $error = ''; - if(!isset($_POST['captcha'])) // page création d'un compte rechargée - { - //$error = ''; - } - elseif($captcha_try == 0) - { - $error = 'error_non_valid_captcha'; - } - elseif($captcha_solution == 0) - { - //$error = ''; - } - elseif($captcha_try != $captcha_solution) // le test! - { - $error = 'bad_solution_captcha'; - } - elseif(!isset($_POST['password']) || empty($_POST['password']) - || (!isset($_POST['login']) || empty($_POST['login']))) - { - $error = 'bad_login_or_password'; - } - else - { - $login = Security::secureString($_POST['login']); - $password = Security::secureString($_POST['password']); - - // -> prévenir la validation par erreur d'une chaine "vide" - $login = removeSpacesTabsCRLF($login); - $password = removeSpacesTabsCRLF($password); - - // conformité - if(isset($password) && isset($login) - && $password == $_POST['password'] && $login == $_POST['login']) - { - unset($_SESSION['captcha']); - - // enregistrement et redirection - $password = password_hash($password, PASSWORD_DEFAULT); - $user = new App\Entity\User($login, $password); - $entityManager->persist($user); - $entityManager->flush(); - - header('Location: ' . new URL); - exit(); - } - else - { - $error = 'bad_login_or_password'; - - // compteur dans la session et blocage de compte - } - } - - // inséré dans $captchaHtml puis dans $formulaireNouveauMDP - $captcha = new Captcha; - // enregistrement de la réponse du captcha pour vérification - $_SESSION['captcha'] = $captcha->getSolution(); - - - // I - affichage - $title = 'Bienvenue nageur bigouden'; - $subHeading = 'Veuillez choisir les codes que vous utiliserez pour gérer le site.'; - - // même vue que la fonction changerMotDePasse() - require('../src/view/password.php'); - - echo($header); - if($error != '') - { - sleep(1); - echo($error_messages[$error]); - } - echo($formulaireNouveauMDP); - echo($error_messages['forbidden_characters']); - echo($footer); - die; -} - - -function connect(LoginBuilder $builder, EntityManager $entityManager) -{ - // déjà connecté - if($_SESSION['admin']) - { - header('Location: ' . new URL); - die; - } - - // II - traitement - $_SESSION['user'] = ''; - $_SESSION['admin'] = false; - - $captcha_solution = (isset($_SESSION['captcha']) && is_int($_SESSION['captcha'])) ? $_SESSION['captcha'] : 0; - $captcha_try = isset($_POST['captcha']) ? Captcha::controlInput($_POST['captcha']) : 0; - - $error = ''; - if(!isset($_POST['captcha'])) // page rechargée - { - //$error = ''; - } - elseif($captcha_try == 0) - { - $error = 'error_non_valid_captcha'; - } - elseif($captcha_solution == 0) - { - //$error = ''; - } - elseif($captcha_try != $captcha_solution) // le test! - { - $error = 'bad_solution_captcha'; - } - elseif(!isset($_POST['login']) || empty($_POST['login']) - || !isset($_POST['password']) || empty($_POST['password'])) - { - $error = 'bad_login_or_password'; - } - else // c'est OK - { - $login = Security::secureString($_POST['login']); - $password = Security::secureString($_POST['password']); - $user = getUser($login, $entityManager); - - // enregistrement et redirection - if(!empty($user) && $login === $user->getLogin() && password_verify($password, $user->getPassword())) - { - $log = new Log(true); - $entityManager->persist($log); - $entityManager->flush(); - - session_regenerate_id(true); // protection fixation de session, si l'attaquant a créé un cookie de session (attaque XSS), il est remplacé - //unset($_SESSION['captcha']); - $_SESSION['user'] = $login; - $_SESSION['admin'] = true; - $link = new URL(isset($_GET['from']) ? ['page' => $_GET['from']] : []); - isset($_GET['id']) ? $link->addParams(['id' => $_GET['id']]) : ''; - header('Location: ' . $link); - die; - } - else - { - $log = new Log(false); - $entityManager->persist($log); - $entityManager->flush(); - $error = 'bad_login_or_password'; - } - } - - // inséré dans $captchaHtml puis dans $formulaireNouveauMDP - $captcha = new Captcha; - // enregistrement de la réponse du captcha pour vérification - $_SESSION['captcha'] = $captcha->getSolution(); // int - - // I - affichage - $title = "Connexion"; - $subHeading = "Veuillez saisir votre identifiant (e-mail) et votre mot de passe."; - - require('../src/view/password.php'); - - //$builder->addHTML($header); - if($error != '') - { - sleep(1); - $builder->addHTML($error_messages[$error]); - } - $builder->addHTML($formulaireConnexion); - //$builder->addHTML($warning_messages['message_cookie']); - $builder->addHTML($warning_messages['private_browsing']); - $builder->addHTML($footer); - - //die; -} - - -function changePassword(EntityManager $entityManager): void -{ - // fonction exécutée à priori deux fois d'affilée: affichage puis traitement de la saisie - - // II - traitement - $error = ''; - $success = false; - if(empty($_POST)) // première fois ou page rechargée - { - // - } - elseif(!isset($_POST['login']) || empty($_POST['login']) - || !isset($_POST['old_password']) || empty($_POST['old_password']) - || !isset($_POST['new_password']) || empty($_POST['new_password']) - || !isset($_POST['modify_password_hidden']) || !empty($_POST['modify_password_hidden'])) - { - $error = 'bad_login_or_password'; - } - else - { - // sécurisation de la saisie - $new_password = Security::secureString($_POST['new_password']); - $login = Security::secureString($_POST['login']); - $old_password = Security::secureString($_POST['old_password']); - - // éviter d'enregistrer une chaîne vide - $new_password = removeSpacesTabsCRLF($new_password); - - // tests de conformité - if($login != $_POST['login'] || $old_password != $_POST['old_password'] || $new_password != $_POST['new_password']) - { - $error = 'forbidden_characters'; - } - elseif($login !== $_SESSION['user']){ - $error = 'bad_login_or_password'; - } - else - { - $user = getUser($login, $entityManager); - - if(password_verify($old_password, $user->getPassword())) - { - // enregistrement et redirection - $new_password = password_hash($new_password, PASSWORD_DEFAULT); - $user->setPassword($new_password); - $entityManager->flush(); - $success = true; - } - else - { - $error = 'bad_login_or_password'; - } - } - } - - - // I - affichage - $title = "Nouveau mot de passe"; - $subHeading = "Veuillez vous identifier à nouveau puis saisir votre nouveau mot de passe."; - - require('../src/view/password.php'); - - echo($header); - if($error != '') - { - sleep(1); // sécurité TRÈS insuffisante à la force brute - echo($error_messages[$error]); - } - elseif($success) - { - $success = false; - echo($alertJSNewPassword); - //header("Location: " . new URL(['page' => $_GET['from']])); // choisir "location" entre PHP et JS - die; - } - echo($formulaireModifMDP); - echo($footer); - die; -} - - -function getUser(string $login, EntityManager $entityManager): ?User -{ - $users = $entityManager->getRepository('App\Entity\User')->findBy(['login' => $login]); - - if(count($users) === 0) - { - $_SESSION['user'] = ''; - $_SESSION['admin'] = false; - } - - foreach($users as $user) - { - if($user->getLogin() === $login) - { - return $user; - } - } - return null; -} - - -function disconnect() -{ - // nettoyage complet - $_SESSION = []; // mémoire vive - session_destroy(); // fichier côté serveur - setcookie('PHPSESSID', '', time() - 4200, '/'); // cookie de session - $link = new URL(['page' => $_GET['page']]); - isset($_GET['id']) ? $link->addParams(['id' => $_GET['id']]) : ''; - header('Location: ' . $link); - die; -} \ No newline at end of file diff --git a/src/installation.php b/src/installation.php index 295c583..eaf2181 100644 --- a/src/installation.php +++ b/src/installation.php @@ -92,7 +92,8 @@ function makeStartPage(EntityManager $entityManager){ // paramètres: name_page, end_of_path, reachable, in_menu, hidden, position, parent $accueil = new Page('Accueil', 'accueil', true, true, false, 1, NULL); $article = new Page('Article', 'article', true, false, false, NULL, NULL); - $connection = new Page('Connexion', 'connexion', true, false, false, NULL, NULL); + $connection = new Page('Connexion', 'connection', true, false, false, NULL, NULL); + $my_account = new Page('Mon compte', 'user_edit', true, false, false, NULL, NULL); $menu_paths = new Page("Menu et chemins", 'menu_chemins', true, false, false, NULL, NULL); //$edit_page = new Page("Modification d'une page", 'modif_page', true, false, false, NULL, NULL); // pas de page "Modification de la page" $new_page = new Page('Nouvelle page', 'nouvelle_page', true, false, false, NULL, NULL); @@ -108,6 +109,8 @@ function makeStartPage(EntityManager $entityManager){ $breadcrumb = new Node('breadcrumb', NULL, [], 2, $header, NULL, NULL); $head_login = new Node('head', NULL, ["stop" => true, 'css_array' => ['body', 'head', 'nav'], 'js_array' => ['main']], 1, NULL, $connection, NULL); $login = new Node('login', NULL, [], 1, $main, $connection, NULL); + $head_my_account = new Node('head', NULL, ["stop" => true, 'css_array' => ['body', 'head', 'nav'], 'js_array' => ['main']], 1, NULL, $my_account, NULL); + $user_edit = new Node('user_edit', NULL, [], 1, $main, $my_account, NULL); $head_edit_menu = new Node('head', NULL, ['css_array' => ['body', 'head', 'nav', 'menu', 'foot'], 'js_array' => ['main', 'menu']], 1, NULL, $menu_paths, NULL); $bloc_edit_menu = new Node('menu', NULL, [], 1, $main, $menu_paths, NULL); $head_new_page = new Node('head', NULL, ['css_array' => ['body', 'head', 'nav', 'new_page', 'foot'], 'js_array' => ['main', 'new_page']], 1, NULL, $new_page, NULL); @@ -123,8 +126,9 @@ function makeStartPage(EntityManager $entityManager){ /* -- table node_data -- */ // paramètres: data, node, images - $head_accueil_data = new NodeData(["description" => "page d'accueil"], $head_accueil, new ArrayCollection([$favicon])); + $head_accueil_data = new NodeData(["description" => "Page d'accueil"], $head_accueil, new ArrayCollection([$favicon])); $head_login_data = new NodeData(["description" => "Connexion"], $head_login, new ArrayCollection([$favicon])); + $head_my_account_data = new NodeData(["description" => "Mon compte"], $head_my_account, new ArrayCollection([$favicon])); $head_article_data = new NodeData(["description" => ""], $head_article, new ArrayCollection([$favicon])); $head_edit_menu_data = new NodeData(["description" => "Menu et chemins"], $head_edit_menu, new ArrayCollection([$favicon])); $head_new_page_data = new NodeData(["description" => "Nouvelle page"], $head_new_page, new ArrayCollection([$favicon])); @@ -137,6 +141,7 @@ function makeStartPage(EntityManager $entityManager){ $entityManager->persist($accueil); $entityManager->persist($article); $entityManager->persist($connection); + $entityManager->persist($my_account); $entityManager->persist($menu_paths); //$entityManager->persist($edit_page); // pas de page "Modification de la page" $entityManager->persist($new_page); @@ -150,6 +155,8 @@ function makeStartPage(EntityManager $entityManager){ $entityManager->persist($breadcrumb); $entityManager->persist($head_login); $entityManager->persist($login); + $entityManager->persist($head_my_account); + $entityManager->persist($user_edit); $entityManager->persist($head_article); $entityManager->persist($head_edit_menu); $entityManager->persist($bloc_edit_menu); @@ -168,6 +175,7 @@ function makeStartPage(EntityManager $entityManager){ $entityManager->persist($header_data); $entityManager->persist($footer_data); $entityManager->persist($head_login_data); + $entityManager->persist($head_my_account_data); $entityManager->persist($head_article_data); $entityManager->persist($head_edit_menu_data); $entityManager->persist($head_new_page_data); diff --git a/src/model/entities/Image.php b/src/model/entities/Image.php index 181c137..302a27f 100644 --- a/src/model/entities/Image.php +++ b/src/model/entities/Image.php @@ -74,7 +74,7 @@ class Image } - // pour ViewBuilder? + // pour ViewBuilderController? /*public function displayImage($imageId): void { //$imageId = 1; // Exemple d'ID d'image diff --git a/src/model/entities/User.php b/src/model/entities/User.php index 4b1dcb8..26802e2 100644 --- a/src/model/entities/User.php +++ b/src/model/entities/User.php @@ -35,11 +35,14 @@ class User { return $this->login; } + public function setLogin(string $login): void + { + $this->login = $login; + } public function getPassword(): string { return $this->password; } - public function setPassword(string $password): void { $this->password = $password; diff --git a/src/request_router.php b/src/request_router.php deleted file mode 100644 index 0b31755..0000000 --- a/src/request_router.php +++ /dev/null @@ -1,256 +0,0 @@ -: position = nombre d'éléments de la fraterie + 1, l'élément précédent devient le parent - if($_GET['menu_edit'] === 'move_one_level_down' && isset($json['id'])){ - MenuAndPathsController::MoveOneLevelDown($entityManager, $json); - } - - if($_GET['menu_edit'] === 'switch_positions' && isset($json['id1']) && isset($json['id2'])){ - MenuAndPathsController::switchPositions($entityManager, $json); - } - - if($_GET['menu_edit'] === 'displayInMenu' && isset($json['id']) && isset($json['checked'])){ - MenuAndPathsController::displayInMenu($entityManager, $json); - } - } - - /* -- mode Modification d'une page -- */ - // partie "page" - elseif(isset($_GET['page_edit'])) - { - // titre de la page - if($_GET['page_edit'] === 'page_title'){ - PageManagementController::setPageTitle($entityManager, $json); - } - // description dans les métadonnées - elseif($_GET['page_edit'] === 'page_description'){ - PageManagementController::setPageDescription($entityManager, $json); - } - } - - // partie "blocs" - elseif(isset($_GET['bloc_edit'])) - { - // renommage d'un bloc - if($_GET['bloc_edit'] === 'rename_page_bloc') - { - PageManagementController::renameBloc($entityManager, $json); - } - // inversion des positions de deux blocs - elseif($_GET['bloc_edit'] === 'switch_blocs_positions') - { - PageManagementController::SwitchBlocsPositions($entityManager, $json); - } - } - - /* -- upload d'image dans tinymce par copier-coller -- */ - // collage de HTML contenant une ou plusieurs balises - if(isset($_GET['action']) && $_GET['action'] == 'upload_image_html'){ - ImageUploadController::uploadImageHtml(); - } - // collage d'une image (code base64 dans le presse-papier) non encapsulée dans du HTML - elseif(isset($_GET['action']) && $_GET['action'] == 'upload_image_base64'){ - ImageUploadController::uploadImageBase64(); - } - - /* -- requêtes spécifiques au calendrier -- */ - if($_GET['action'] === 'new_event'){ - CalendarController::newEvent($json, $entityManager); - } - elseif($_GET['action'] === 'update_event'){ - CalendarController::updateEvent($json, $entityManager); - } - elseif($_GET['action'] === 'remove_event'){ - CalendarController::removeEvent($json, $entityManager); - } - else{ - echo json_encode(['success' => false]); - } - die; - } - - // upload d'image dans tinymce avec le plugin (bouton "insérer une image" de l'éditeur) - elseif(strpos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') !== false && isset($_GET['action']) && $_GET['action'] === 'upload_image') - { - ImageUploadController::imageUploadTinyMce(); - } - // requêtes XMLHttpRequest - elseif(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') - { - //echo "requête XMLHttpRequest reçue par le serveur"; - echo json_encode(['success' => false]); // ça marche mais ça marche pas... - die; - } - - /* -- envoi d'un formulaire HTML -- */ - elseif($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded') - { - /* -- nouvelle page -- */ - if(isset($_POST['page_name']) && $_POST['page_name'] !== null - && isset($_POST['page_name_path']) && $_POST['page_name_path'] !== null - && isset($_POST['page_location']) && $_POST['page_location'] !== null - && isset($_POST['page_description']) && $_POST['page_description'] !== null - && isset($_POST['new_page_hidden']) && $_POST['new_page_hidden'] === '') - { - PageManagementController::newPage($entityManager); - } - - /* -- suppression d'une page -- */ - elseif(isset($_POST['page_id']) && $_POST['page_id'] !== null - && isset($_POST['submit_hidden']) && $_POST['submit_hidden'] === '') - { - PageManagementController::deletePage($entityManager); - } - - /* -- mode Modification d'une page -- */ - - // modification du chemins en snake_case - elseif(isset($_POST['page_menu_path']) && $_POST['page_menu_path'] !== null - && isset($_POST['page_id']) && $_POST['page_id'] !== null - && isset($_POST['page_name_path_hidden']) && $_POST['page_name_path_hidden'] === '') - { - PageManagementController::updatePageMenuPath($entityManager); - } - // ajout d'un bloc dans une page - elseif(isset($_POST['bloc_title']) && $_POST['bloc_title'] !== null - && isset($_POST['bloc_select']) && $_POST['bloc_select'] !== null - && isset($_POST['bloc_title_hidden']) && $_POST['bloc_title_hidden'] === '') // contrôle anti-robot avec input hidden - { - PageManagementController::addBloc($entityManager); - } - // suppression d'un bloc de page - elseif(isset($_POST['delete_bloc_id']) && $_POST['delete_bloc_id'] !== null - && isset($_POST['delete_bloc_hidden']) && $_POST['delete_bloc_hidden'] === '') // contrôle anti-robot avec input hidden - { - PageManagementController::deleteBloc($entityManager); - } - - - /* -- page Menu et chemins -- */ - - // création d'une entrée de menu avec une URL - elseif(isset($_POST["label_input"]) && isset($_POST["url_input"]) && isset($_POST["location"])){ - MenuAndPathsController::newUrlMenuEntry($entityManager); - } - // suppression d'une entrée de menu avec une URL - elseif(isset($_POST['delete']) && isset($_POST['x']) && isset($_POST['y'])){ // 2 params x et y sont là parce qu'on a cliqué sur une image - MenuAndPathsController::deleteUrlMenuEntry($entityManager); - } - - // redirection page d'accueil - else{ - header("Location: " . new URL(['error' => 'paramètres inconnus'])); - die; - } - } - } -} - -// cas particulier d'un GET ajax non-admin par fullcalendar -elseif($_SERVER['REQUEST_METHOD'] === 'GET'){ - /* -- non-admin -- */ - // chargement des évènements à la création du calendrier - // et au changement de dates affichées (boutons flèches mais pas changement de vue) - if($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['action']) && $_GET['action'] === 'get_events' - && isset($_GET['start']) && isset($_GET['end']) && empty($_POST)) - { - CalendarController::getData($entityManager); - } - - if($_SESSION['admin'] === true){ - // ... - } -} \ No newline at end of file diff --git a/src/router.php b/src/router.php new file mode 100644 index 0000000..19fe1c1 --- /dev/null +++ b/src/router.php @@ -0,0 +1,302 @@ + 1er test, méthode http: GET, POST ou autre chose +=> 2ème test, type de contenu (méthode POST uniquement): +"application/x-www-form-urlencoded" = formulaire +"application/json" = requête AJAX avec fetch() +"multipart/form-data" = upload d'image par tinymce +$_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' requête AJAX xhs, non utilisée +=> 3ème test, comme le 2ème test mais uniquement si $_SESSION['admin'] est vrai +*/ + +declare(strict_types=1); + + +if($_SERVER['REQUEST_METHOD'] === 'GET'){ + // table "user" vide + if(!UserController::existUsers($entityManager)){ + require '../src/view/templates/user_create.php'; + die; + } + + // bouton déconnexion + if($request->query->has('action') && $request->query->get('action') === 'deconnection') + { + UserController::disconnect($entityManager); + } + + // données du calendrier + // création du calendrier et changement de dates affichées (boutons flèches mais pas changement de vue) + if($_SERVER['REQUEST_METHOD'] === 'GET' && $request->query->has('action') && $request->query->get('action') === 'get_events' + && $request->query->has('start') && $request->query->has('end') && empty($_POST)) + { + CalendarController::getData($entityManager); + } + + if($_SESSION['admin'] === true){ + // ... + } + + // construction d'une page + $response = new ViewController()->buildView($request, $entityManager); +} + + +elseif($_SERVER['REQUEST_METHOD'] === 'POST'){ + /* -- contrôleurs appellables par tout le monde -- */ + + // table "user" vide + if(!UserController::existUsers($entityManager)) + { + UserController::createUser($entityManager); + } + + // requêtes JSON avec fetch() + if($_SERVER['CONTENT_TYPE'] === 'application/json') + { + $data = file_get_contents('php://input'); + $json = json_decode($data, true); + + if(isset($_GET['action'])) + { + // formulaire de contact + if($_GET['action'] === 'send_email'){ + EmailController::submit($json, $entityManager); + } + } + } + + // envoi formulaire HTML + elseif($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded'){ + // tentative de connexion + if($request->query->has('action') && $request->query->get('action') === 'connection'){ + //$response = + UserController::connect($entityManager); + } + } + + + if($_SESSION['admin'] === true) + { + /* -- requêtes AJAX -- */ + + // requêtes JSON avec fetch() + if($_SERVER['CONTENT_TYPE'] === 'application/json') + { + $data = file_get_contents('php://input'); + $json = json_decode($data, true); + + if(isset($_GET['action'])) + { + /* -- manipulation des articles -- */ + if($_GET['action'] === 'editor_submit' && isset($json['id']) && isset($json['content'])) + { + ArticleController::editorSubmit($entityManager, $json); + } + elseif($_GET['action'] === 'delete_article' && isset($json['id'])) + { + ArticleController::deleteArticle($entityManager, $json); + } + // inversion de la position de deux noeuds + elseif($_GET['action'] === 'switch_positions' && isset($json['id1']) && isset($json['id2'])) + { + ArticleController::switchPositions($entityManager, $json); + } + elseif($_GET['action'] === 'date_submit' && isset($json['id']) && isset($json['date'])) + { + ArticleController::dateSubmit($entityManager, $json); + } + + /* -- bloc Formulaire -- */ + elseif($_GET['action'] === 'recipient_email'){ + ContactFormController::updateRecipient($entityManager, $json); + } + elseif($_GET['action'] === 'test_email'){ + ContactFormController::sendTestEmail($entityManager, $json); + } + } + + /* -- page Menu et chemins -- */ + elseif(isset($_GET['menu_edit'])) + { + // récupération des données (serait peut-être mieux dans la classe) + Director::$menu_data = new Menu($entityManager); + + // flèche gauche <=: position = position du parent + 1, parent = grand-parent, recalculer les positions + if($_GET['menu_edit'] === 'move_one_level_up' && isset($json['id'])){ + MenuAndPathsController::MoveOneLevelUp($entityManager, $json); + } + + // flèche droite =>: position = nombre d'éléments de la fraterie + 1, l'élément précédent devient le parent + if($_GET['menu_edit'] === 'move_one_level_down' && isset($json['id'])){ + MenuAndPathsController::MoveOneLevelDown($entityManager, $json); + } + + if($_GET['menu_edit'] === 'switch_positions' && isset($json['id1']) && isset($json['id2'])){ + MenuAndPathsController::switchPositions($entityManager, $json); + } + + if($_GET['menu_edit'] === 'displayInMenu' && isset($json['id']) && isset($json['checked'])){ + MenuAndPathsController::displayInMenu($entityManager, $json); + } + } + + /* -- mode Modification d'une page -- */ + // partie "page" + elseif(isset($_GET['page_edit'])) + { + // titre de la page + if($_GET['page_edit'] === 'page_title'){ + PageManagementController::setPageTitle($entityManager, $json); + } + // description dans les métadonnées + elseif($_GET['page_edit'] === 'page_description'){ + PageManagementController::setPageDescription($entityManager, $json); + } + } + + // partie "blocs" + elseif($request->query->has('bloc_edit')) + { + // renommage d'un bloc + if($request->query->get('bloc_edit') === 'rename_page_bloc') + { + PageManagementController::renameBloc($entityManager, $json); + } + // inversion des positions de deux blocs + elseif($request->query->get('bloc_edit') === 'switch_blocs_positions') + { + PageManagementController::SwitchBlocsPositions($entityManager, $json); + } + } + + /* -- upload d'image dans tinymce par copier-coller -- */ + // collage de HTML contenant une ou plusieurs balises + if($request->query->has('action') && $request->query->get('action') == 'upload_image_html'){ + ImageUploadController::uploadImageHtml(); + } + // collage d'une image (code base64 dans le presse-papier) non encapsulée dans du HTML + elseif($request->query->has('action') && $request->query->get('action') == 'upload_image_base64'){ + ImageUploadController::uploadImageBase64(); + } + + /* -- requêtes spécifiques au calendrier -- */ + if($request->query->get('action') === 'new_event'){ + CalendarController::newEvent($json, $entityManager); + } + elseif($request->query->get('action') === 'update_event'){ + CalendarController::updateEvent($json, $entityManager); + } + elseif($request->query->get('action') === 'remove_event'){ + CalendarController::removeEvent($json, $entityManager); + } + else{ + echo json_encode(['success' => false]); + } + die; + } + + // upload d'image dans tinymce avec le plugin (bouton "insérer une image" de l'éditeur) + elseif(strpos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') !== false && $request->query->has('action') && $request->query->get('action') === 'upload_image') + { + ImageUploadController::imageUploadTinyMce(); + } + // requêtes XMLHttpRequest + elseif(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') + { + //echo "requête XMLHttpRequest reçue par le serveur"; + echo json_encode(['success' => false]); // ça marche mais ça marche pas... + die; + } + + /* -- envoi formulaire HTML -- */ + elseif($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded') + { + /* -- nouvelle page -- */ + if(isset($_POST['page_name']) && $_POST['page_name'] !== null + && isset($_POST['page_name_path']) && $_POST['page_name_path'] !== null + && isset($_POST['page_location']) && $_POST['page_location'] !== null + && isset($_POST['page_description']) && $_POST['page_description'] !== null + && isset($_POST['new_page_hidden']) && $_POST['new_page_hidden'] === '') + { + PageManagementController::newPage($entityManager); + } + + /* -- suppression d'une page -- */ + elseif(isset($_POST['page_id']) && $_POST['page_id'] !== null + && isset($_POST['submit_hidden']) && $_POST['submit_hidden'] === '') + { + PageManagementController::deletePage($entityManager); + } + + /* -- mode Modification d'une page -- */ + + // modification du chemins en snake_case + elseif(isset($_POST['page_menu_path']) && $_POST['page_menu_path'] !== null + && isset($_POST['page_id']) && $_POST['page_id'] !== null + && isset($_POST['page_name_path_hidden']) && $_POST['page_name_path_hidden'] === '') + { + PageManagementController::updatePageMenuPath($entityManager); + } + // ajout d'un bloc dans une page + elseif(isset($_POST['bloc_title']) && $_POST['bloc_title'] !== null + && isset($_POST['bloc_select']) && $_POST['bloc_select'] !== null + && isset($_POST['bloc_title_hidden']) && $_POST['bloc_title_hidden'] === '') // contrôle anti-robot avec input hidden + { + PageManagementController::addBloc($entityManager); + } + // suppression d'un bloc de page + elseif(isset($_POST['delete_bloc_id']) && $_POST['delete_bloc_id'] !== null + && isset($_POST['delete_bloc_hidden']) && $_POST['delete_bloc_hidden'] === '') // contrôle anti-robot avec input hidden + { + PageManagementController::deleteBloc($entityManager); + } + + + /* -- page Menu et chemins -- */ + + // création d'une entrée de menu avec une URL + elseif(isset($_POST["label_input"]) && isset($_POST["url_input"]) && isset($_POST["location"])){ + MenuAndPathsController::newUrlMenuEntry($entityManager); + } + // suppression d'une entrée de menu avec une URL + elseif(isset($_POST['delete']) && isset($_POST['x']) && isset($_POST['y'])){ // 2 params x et y sont là parce qu'on a cliqué sur une image + MenuAndPathsController::deleteUrlMenuEntry($entityManager); + } + + + /* -- page Mon compte -- */ + elseif($request->query->has('action') && $request->query->get('action') === 'update_username') + { + UserController::updateUsername($entityManager); + } + elseif($request->query->has('action') && $request->query->get('action') === 'update_password') + { + UserController::updatePassword($entityManager); + } + + // redirection page d'accueil + else{ + header("Location: " . new URL(['error' => 'paramètres inconnus'])); + die; + } + } + } + + // rien ne match + header("Location: " . new URL); + die; +} + + +else{ + header("Location: " . new URL(['error' => 'tu fais quoi là mec?'])); + die; +} + +// enlever le test isset à terme +if(isset($response)){ + $response->send(); +} \ No newline at end of file diff --git a/src/view/FooterBuilder.php b/src/view/FooterBuilder.php index 14f9cd7..8a519f8 100644 --- a/src/view/FooterBuilder.php +++ b/src/view/FooterBuilder.php @@ -28,7 +28,7 @@ class FooterBuilder extends AbstractBuilder if($_SESSION['admin']) { $empty_admin_zone = 'empty_admin_zone'; - $link_edit_page = new URL(['page' => CURRENT_PAGE]); + $link_edit_page = CURRENT_PAGE === 'article' ? new URL(['page' => 'accueil']) : new URL(['page' => CURRENT_PAGE]); if(MainBuilder::$modif_mode){ $mode = 'modification de page'; $div_admin = 'logged_in modif_mode'; @@ -43,10 +43,10 @@ class FooterBuilder extends AbstractBuilder $link_new_page = new URL(['page' => 'nouvelle_page']); $link_change_paths = new URL(['page' => 'menu_chemins']); - $link_change_password = new URL(['from' => CURRENT_PAGE, 'action' => 'modif_mdp']); + $link_change_password = new URL(['page' => 'user_edit', 'from' => CURRENT_PAGE]); isset($_GET['id']) ? $link_change_password->addParams(['id' => $_GET['id']]) : ''; - $link_logout = new URL(['page' => CURRENT_PAGE, 'action' => 'deconnexion']); + $link_logout = new URL(['action' => 'deconnection', 'from' => CURRENT_PAGE]); isset($_GET['id']) ? $link_logout->addParams(['id' => $_GET['id']]) : ''; $zone_admin = '
@@ -54,7 +54,7 @@ class FooterBuilder extends AbstractBuilder '
' . "\n" . '
' . "\n" . '
' . "\n" . - '
' . "\n" . + '
' . "\n" . '
' . "\n" . '
' . "\n"; } diff --git a/src/view/LoginBuilder.php b/src/view/LoginBuilder.php index 532f054..567c93d 100644 --- a/src/view/LoginBuilder.php +++ b/src/view/LoginBuilder.php @@ -9,9 +9,44 @@ class LoginBuilder extends AbstractBuilder { public function __construct(Node $node) { - global $entityManager; + // déjà connecté? + if($_SESSION['admin']) + { + header('Location: ' . new URL); + die; + } - // une classe Password ce serait pas mal!! - connect($this, $entityManager); + $viewFile = self::VIEWS_PATH . $node->getName() . '.php'; + + $captcha = new Captcha; + $_SESSION['captcha'] = $captcha->getSolution(); // enregistrement de la réponse du captcha pour vérification + + //$this->html .= $header; + + $error_messages = [ + 'error_non_valid_captcha' => 'Erreur au test anti-robot, veuillez saisir un nombre entier.', + 'captcha_server_error' => 'captcha_server_error', + 'bad_solution_captcha' => 'Erreur au test anti-robot, veuillez réessayer.', + 'bad_login_or_password' => 'Mauvais identifiant ou mot de passe, veuillez réessayer.', // ne pas indiquer où est l'erreur + 'forbidden_characters' => 'Caractères interdits: espaces, tabulations, sauts CR/LF.' + ]; + + $link_form = new URL(['action' => 'connection']); + isset($_GET['from']) ? $link_form->addParams(['from' => $_GET['from']]) : ''; + isset($_GET['id']) ? $link_form->addParams(['id' => $_GET['id']]) : ''; + + $link_exit = new URL; + isset($_GET['from']) ? $link_exit->addParams(['page' => $_GET['from'] ]) : ''; + isset($_GET['id']) ? $link_exit->addParams(['id' => $_GET['id']]) : ''; + + $error = isset($_GET['error']) ? $error_messages[$_GET['error']] : ''; + + ob_start(); + require $viewFile; + $this->html = ob_get_clean(); // nouveau contenu + + //$this->html .=

Ce site utilise un cookie « obligatoire » lorsque vous êtes connecté ainsi que sur cette page.
Il sera supprimé à votre déconnexion ou dès que vous aurez quitté le site.

; + + //$this->html .= $footer; } } diff --git a/src/view/MainBuilder.php b/src/view/MainBuilder.php index 7f3a0f0..889df37 100644 --- a/src/view/MainBuilder.php +++ b/src/view/MainBuilder.php @@ -86,7 +86,7 @@ class MainBuilder extends AbstractBuilder //$page_id = Director::$page_path->getLast()->getId(); $head_node = null; - foreach(ViewBuilder::$root_node->getChildren() as $first_level_node){ + foreach(ViewController::$root_node->getChildren() as $first_level_node){ if($first_level_node->getName() === 'head'){ $head_node = $first_level_node; // normallement c'est le 1er enfant break; diff --git a/src/view/UserEditBuilder.php b/src/view/UserEditBuilder.php new file mode 100644 index 0000000..63bbfad --- /dev/null +++ b/src/view/UserEditBuilder.php @@ -0,0 +1,58 @@ +getName() . '.php'; + + $error_messages = [ + 'error_non_valid_captcha' => 'Erreur au test anti-robot, veuillez saisir un nombre entier.', + 'captcha_server_error' => 'captcha_server_error', + + 'bad_login_or_password' => 'Mauvais identifiant ou mot de passe, veuillez réessayer.', // ne pas indiquer où est l'erreur + 'bad_solution_captcha' => 'Erreur au test anti-robot, veuillez réessayer.', + 'forbidden_characters' => 'Caractères interdits: espaces, tabulations, sauts CR/LF.', + 'same_username_as_before' => 'Nouveau nom identique au précédent.', + 'same_password_as_before' => 'Nouveau mot de passe identique au précédent.' + ]; + + $error_username = isset($_GET['error_login']) ? $error_messages[$_GET['error_login']] : ''; + $success_username = (isset($_GET['success_login']) && $_GET['success_login']) ? 'Identifiant modifié avec succès.' : ''; + $error_password = isset($_GET['error_password']) ? $error_messages[$_GET['error_password']] : ''; + $success_password = (isset($_GET['success_password']) && $_GET['success_password']) ? 'Mot de passe modifié avec succès.' : ''; + + $captcha = new Captcha; + $_SESSION['captcha'] = $captcha->getSolution(); // enregistrement de la réponse du captcha pour vérification + + $link_user_form = new URL(['action' => 'update_username']); + isset($_GET['from']) ? $link_user_form->addParams(['from' => $_GET['from']]) : ''; + isset($_GET['id']) ? $link_user_form->addParams(['id' => $_GET['id']]) : ''; + + $link_password_form = new URL(['action' => 'update_password']); + isset($_GET['from']) ? $link_password_form->addParams(['from' => $_GET['from']]) : ''; + isset($_GET['id']) ? $link_password_form->addParams(['id' => $_GET['id']]) : ''; + + $link_exit = new URL; + isset($_GET['from']) ? $link_exit->addParams(['page' => $_GET['from'] ]) : ''; + isset($_GET['id']) ? $link_exit->addParams(['id' => $_GET['id']]) : ''; + + ob_start(); + require $viewFile; + $this->html = ob_get_clean(); // nouveau contenu + } +} \ No newline at end of file diff --git a/src/view/ViewBuilder.php b/src/view/ViewBuilder.php deleted file mode 100644 index 2e2fea6..0000000 --- a/src/view/ViewBuilder.php +++ /dev/null @@ -1,18 +0,0 @@ -useChildrenBuilder($root_node); - } -} diff --git a/src/view/password.php b/src/view/password.php deleted file mode 100644 index 77f8736..0000000 --- a/src/view/password.php +++ /dev/null @@ -1,155 +0,0 @@ - -

Montrez que vous n'êtes pas un robot.
- - -

- 'connexion']); -isset($_GET['from']) ? $link->addParams(['from' => $_GET['from']]) : ''; -isset($_GET['id']) ? $link->addParams(['id' => $_GET['id']]) : ''; -ob_start(); -?> -
-

-

-

-

- - - - -
- -
-

-

-

-

- - - - -
- 'modif_mdp']); -isset($_GET['from']) ? $link->addParams(['from' => $_GET['from']]) : ''; -isset($_GET['id']) ? $link->addParams(['id' => $_GET['id']]) : ''; -ob_start(); -?> -
- -

- -

- - - -

- -
- - - - - - - <?= $title ?> - - - - - - - - -
-

-

- '

Erreur au test anti-robot, veuillez saisir un nombre entier.

', - 'bad_solution_captcha' => '

Erreur au test anti-robot, veuillez réessayer.

', - 'bad_login_or_password' => '

Mauvais identifiant ou mot de passe, veuillez réessayer.

', // ne pas indiquer où est l'erreur - 'forbidden_characters' => '

Caractères interdits: espaces, tabulations, sauts CR/LF.

' -]; - -$warning_messages = [ - 'message_disconnect' => "

N'oubliez de cliquer sur 'déconnexion' quand vous aurez fini.

", - //'message_cookie' => "

Ce site utilise un cookie « obligatoire » lorsque vous êtes connecté ainsi que sur cette page.
Il sera supprimé à votre déconnexion ou dès que vous aurez quitté le site.

", - 'private_browsing' =>"

Au fait? Vous n'utilisez pas votre propre ordinateur ou téléphone?
- Utilisez la navigation privée.

" -]; - - -// confirmation modification du mot de passe -$page = isset($_GET['from']) ? $_GET['from'] : 'accueil'; -$id = isset($_GET['id']) ? ', \'' . $_GET['id'] . '\'' : ''; -$js = "newPassword('" . $page . "'" . $id . ");"; -ob_start(); -?> - - -addParams(['page' => $_GET['from'] ]) : ''; -isset($_GET['id']) ? $link->addParams(['id' => $_GET['id']]) : ''; -ob_start(); -if(isset($_GET['from'])) // exclue la "création du mot de passe" -{ -?> -

- - - -

- +
+

Connexion à l'espace d'administration

+ +
\ No newline at end of file diff --git a/src/view/templates/user_create.php b/src/view/templates/user_create.php new file mode 100644 index 0000000..dd17547 --- /dev/null +++ b/src/view/templates/user_create.php @@ -0,0 +1,52 @@ + 'Erreur au test anti-robot, veuillez saisir un nombre entier.', + 'captcha_server_error' => 'captcha_server_error', + 'bad_solution_captcha' => 'Erreur au test anti-robot, veuillez réessayer.', + 'different_passwords' => 'Les deux mots de passe saisis sont différents', + 'forbidden_characters' => 'Caractères interdits: espaces, tabulations, sauts CR/LF.' +]; +$error = isset($_GET['error']) ? $error_messages[$_GET['error']] : ''; + +$captcha = new Captcha; +$_SESSION['captcha'] = $captcha->getSolution(); // enregistrement de la réponse du captcha pour vérification +?> + + + + + Bienvenue + + + + + +
+
+

Bienvenue.

+

Veuillez choisir les codes que vous utiliserez pour gérer le site.

+ +
+
+ + \ No newline at end of file diff --git a/src/view/templates/user_edit.php b/src/view/templates/user_edit.php new file mode 100644 index 0000000..b4b35ed --- /dev/null +++ b/src/view/templates/user_edit.php @@ -0,0 +1,62 @@ + +
+
+
+

Mon compte

+
+ +
+
+
+
+ + +
+ +
\ No newline at end of file -- cgit v1.2.3