Loading index.php +19 Changes for index.php: 19 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -8,8 +8,12 @@ require_once 'src/controllers/accueil.php'; require_once 'src/controllers/pageRecette.php'; require_once 'src/controllers/pageConnexion.php'; require_once 'src/controllers/connexion.php'; try{ session_start(); // Si 'action' n'est pas défini, on charge la page d'accueil if(! isset($_GET['action']) || empty($_GET['action'])){ pageAccueil(3); Loading @@ -24,6 +28,21 @@ try{ require 'test/tests.php'; break; case 'pageConnexion': $controleur = new PageConnexionControleur(); $controleur->executer(); break; case 'erreurConnexion': $controleur = new PageConnexionControleur(true); $controleur->executer(); break; case 'connexion': $controleur = new ConnexionController(); $controleur->executer(); break; case 'detail-recette': $controleur = new PageRecetteControleur(); $controleur->executer(); Loading src/controllers/connexion.php +48 Changes for src/controllers/connexion.php: 48 added lines, 0 removed lines. Original line number Diff line number Diff line <?php require_once 'src/controllers/controleur.php'; require_once 'src/model/utilisateur.php'; require_once 'src/model/utilisateurManager.php'; class ConnexionController extends Controleur { private static $utilisateur = null; private static $execute = false; public function executer() { if(! isset($_POST['identifiant']) || ! isset($_POST['motDePasse'])) { throw new Exception('Un des champs est manquant pour la connexion.'); } $utilisateur = (new UtilisateurManager)->connecter($_POST['identifiant'], $_POST['motDePasse']); if(is_null($utilisateur)) { header('Location: .?action=erreurConnexion'); exit(); } $_SESSION['idUtilisateur'] = $utilisateur->getId(); if(isset($_SESSION['dernierePage'])){ header('Location: '. $_SESSION['dernierePage']); exit(); } header('Location: .'); } public static function estConnecte() { if(self::$execute) { return self::$utilisateur; } self::$execute = true; if(! isset($_SESSION['idUtilisateur'])) { return false; } self::$utilisateur = (new UtilisateurManager)->getUtilisateur($_SESSION['idUtilisateur']); return self::$utilisateur; } } No newline at end of file src/controllers/pageConnexion.php +16 Changes for src/controllers/pageConnexion.php: 16 added lines, 0 removed lines. Original line number Diff line number Diff line <?php require_once 'src/controllers/controleur.php'; require_once 'templates/connexion.php'; class PageConnexionControleur extends Controleur { private $loginIncorrect; public function __construct($loginIncorrect = false) { $this->loginIncorrect = $loginIncorrect; } public function executer(){ afficherPageConnexion($this->loginIncorrect); } } No newline at end of file templates/connexion.php +30 Changes for templates/connexion.php: 30 added lines, 0 removed lines. Original line number Diff line number Diff line <?php function afficherPageConnexion($loginIncorrect = false) { //TODO styliser la page avec Bootstrap Studio $titre = 'Connexion - Ptit Cuistot'; ob_start(); if($loginIncorrect){ echo '<p style="color: red">Identifiant / mot de passe incorrect</p>'; } ?> <form action=".?action=connexion" method="post"> <label for="identifiant">Nom d'utilisateur / email</label> <input type="text" placeholder="Votre nom d'utilisateur" id="identifiant" name="identifiant"> <br><br> <label for="motDePasse">Mot de passe</label> <input type="password" placeholder="Votre mot de passe" id="motDePasse" name="motDePasse"> <br><br> <input type="submit" value="Connexion"> </form> <?php $contenu = ob_get_clean(); require 'templates/layout.php'; } No newline at end of file templates/layout.php +20 −1 Changes for templates/layout.php: 20 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -5,6 +5,12 @@ <!-- Cette page sera utilisé par les vues --> <?php require_once 'src/controllers/connexion.php'; $connecte = ConnexionController::estConnecte(); ?> <!DOCTYPE html> <html lang="fr"> <head> Loading Loading @@ -33,7 +39,20 @@ <li class="nav-item dropdown show"><a class="dropdown-toggle nav-link" aria-expanded="true" data-bs-toggle="dropdown" href="#">Filtres </a> <div class="dropdown-menu" data-bs-popper="none" style="--bs-body-bg: var(--bs-primary);background: var(--bs-secondary);" data-bs-theme="light"><a class="dropdown-item" href="#" data-bs-theme="light"><span style="color: rgb(42, 57, 144); background-color: rgba(42, 57, 144, 0);">Catégories</span></a><a class="dropdown-item" href="#"><span style="color: rgb(42, 57, 144);">Titre</span></a><a class="dropdown-item" href="#"><span style="color: rgb(42, 57, 144);">Ingredients</span></a></div> </li> </ul><a class="btn btn-primary ms-md-2" role="button" href="#" style="color: #ffffff;border-left-color: var(--bs-btn-border-color);box-shadow: 0px 0px var(--bs-light);font-size: 23px;">Se connecter</a> </ul> <?php //TODO Menu pour les utilisateurs connectés ; pour l'instant, on affiche juste Connecté... ?> <a class="btn btn-primary ms-md-2" role="button" href="?action=pageConnexion" style="color: #ffffff;border-left-color: var(--bs-btn-border-color);box-shadow: 0px 0px var(--bs-light);font-size: 23px;"> <?php if($connecte){ echo 'Connecté'; } else{ echo 'Se connecter'; } ?> </a> </div> </div> </nav> Loading Loading
index.php +19 Changes for index.php: 19 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -8,8 +8,12 @@ require_once 'src/controllers/accueil.php'; require_once 'src/controllers/pageRecette.php'; require_once 'src/controllers/pageConnexion.php'; require_once 'src/controllers/connexion.php'; try{ session_start(); // Si 'action' n'est pas défini, on charge la page d'accueil if(! isset($_GET['action']) || empty($_GET['action'])){ pageAccueil(3); Loading @@ -24,6 +28,21 @@ try{ require 'test/tests.php'; break; case 'pageConnexion': $controleur = new PageConnexionControleur(); $controleur->executer(); break; case 'erreurConnexion': $controleur = new PageConnexionControleur(true); $controleur->executer(); break; case 'connexion': $controleur = new ConnexionController(); $controleur->executer(); break; case 'detail-recette': $controleur = new PageRecetteControleur(); $controleur->executer(); Loading
src/controllers/connexion.php +48 Changes for src/controllers/connexion.php: 48 added lines, 0 removed lines. Original line number Diff line number Diff line <?php require_once 'src/controllers/controleur.php'; require_once 'src/model/utilisateur.php'; require_once 'src/model/utilisateurManager.php'; class ConnexionController extends Controleur { private static $utilisateur = null; private static $execute = false; public function executer() { if(! isset($_POST['identifiant']) || ! isset($_POST['motDePasse'])) { throw new Exception('Un des champs est manquant pour la connexion.'); } $utilisateur = (new UtilisateurManager)->connecter($_POST['identifiant'], $_POST['motDePasse']); if(is_null($utilisateur)) { header('Location: .?action=erreurConnexion'); exit(); } $_SESSION['idUtilisateur'] = $utilisateur->getId(); if(isset($_SESSION['dernierePage'])){ header('Location: '. $_SESSION['dernierePage']); exit(); } header('Location: .'); } public static function estConnecte() { if(self::$execute) { return self::$utilisateur; } self::$execute = true; if(! isset($_SESSION['idUtilisateur'])) { return false; } self::$utilisateur = (new UtilisateurManager)->getUtilisateur($_SESSION['idUtilisateur']); return self::$utilisateur; } } No newline at end of file
src/controllers/pageConnexion.php +16 Changes for src/controllers/pageConnexion.php: 16 added lines, 0 removed lines. Original line number Diff line number Diff line <?php require_once 'src/controllers/controleur.php'; require_once 'templates/connexion.php'; class PageConnexionControleur extends Controleur { private $loginIncorrect; public function __construct($loginIncorrect = false) { $this->loginIncorrect = $loginIncorrect; } public function executer(){ afficherPageConnexion($this->loginIncorrect); } } No newline at end of file
templates/connexion.php +30 Changes for templates/connexion.php: 30 added lines, 0 removed lines. Original line number Diff line number Diff line <?php function afficherPageConnexion($loginIncorrect = false) { //TODO styliser la page avec Bootstrap Studio $titre = 'Connexion - Ptit Cuistot'; ob_start(); if($loginIncorrect){ echo '<p style="color: red">Identifiant / mot de passe incorrect</p>'; } ?> <form action=".?action=connexion" method="post"> <label for="identifiant">Nom d'utilisateur / email</label> <input type="text" placeholder="Votre nom d'utilisateur" id="identifiant" name="identifiant"> <br><br> <label for="motDePasse">Mot de passe</label> <input type="password" placeholder="Votre mot de passe" id="motDePasse" name="motDePasse"> <br><br> <input type="submit" value="Connexion"> </form> <?php $contenu = ob_get_clean(); require 'templates/layout.php'; } No newline at end of file
templates/layout.php +20 −1 Changes for templates/layout.php: 20 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -5,6 +5,12 @@ <!-- Cette page sera utilisé par les vues --> <?php require_once 'src/controllers/connexion.php'; $connecte = ConnexionController::estConnecte(); ?> <!DOCTYPE html> <html lang="fr"> <head> Loading Loading @@ -33,7 +39,20 @@ <li class="nav-item dropdown show"><a class="dropdown-toggle nav-link" aria-expanded="true" data-bs-toggle="dropdown" href="#">Filtres </a> <div class="dropdown-menu" data-bs-popper="none" style="--bs-body-bg: var(--bs-primary);background: var(--bs-secondary);" data-bs-theme="light"><a class="dropdown-item" href="#" data-bs-theme="light"><span style="color: rgb(42, 57, 144); background-color: rgba(42, 57, 144, 0);">Catégories</span></a><a class="dropdown-item" href="#"><span style="color: rgb(42, 57, 144);">Titre</span></a><a class="dropdown-item" href="#"><span style="color: rgb(42, 57, 144);">Ingredients</span></a></div> </li> </ul><a class="btn btn-primary ms-md-2" role="button" href="#" style="color: #ffffff;border-left-color: var(--bs-btn-border-color);box-shadow: 0px 0px var(--bs-light);font-size: 23px;">Se connecter</a> </ul> <?php //TODO Menu pour les utilisateurs connectés ; pour l'instant, on affiche juste Connecté... ?> <a class="btn btn-primary ms-md-2" role="button" href="?action=pageConnexion" style="color: #ffffff;border-left-color: var(--bs-btn-border-color);box-shadow: 0px 0px var(--bs-light);font-size: 23px;"> <?php if($connecte){ echo 'Connecté'; } else{ echo 'Se connecter'; } ?> </a> </div> </div> </nav> Loading