From de3f0c7cb52fa879e47a885e1856e27499a9bf5c Mon Sep 17 00:00:00 2001 From: stiti Date: Sat, 25 May 2024 01:13:18 +0200 Subject: [PATCH] Modification des headers + ajout de cookies de connexion --- .../application/config/autoload.php | 2 +- .../application/controllers/Albums.php | 30 ++++------------- .../application/controllers/Artiste.php | 30 ++++------------- .../application/controllers/Home.php | 16 ++-------- .../controllers/MentionsLegales.php | 15 ++------- .../application/controllers/Musiques.php | 15 ++------- .../application/controllers/Search.php | 30 ++++------------- .../application/controllers/Utilisateur.php | 32 +++++++++++++------ .../application/views/dashboard.php | 4 +-- .../application/views/layout/header_dark.php | 16 ++++++++-- CodeIgniter-3.1.13/assets/css/inscription.css | 6 ++++ 11 files changed, 73 insertions(+), 123 deletions(-) diff --git a/CodeIgniter-3.1.13/application/config/autoload.php b/CodeIgniter-3.1.13/application/config/autoload.php index 7cdc901..01fe0e2 100644 --- a/CodeIgniter-3.1.13/application/config/autoload.php +++ b/CodeIgniter-3.1.13/application/config/autoload.php @@ -89,7 +89,7 @@ $autoload['drivers'] = array(); | | $autoload['helper'] = array('url', 'file'); */ -$autoload['helper'] = array(); +$autoload['helper'] = array('url', 'form', 'html', 'cookie'); /* | ------------------------------------------------------------------- diff --git a/CodeIgniter-3.1.13/application/controllers/Albums.php b/CodeIgniter-3.1.13/application/controllers/Albums.php index de1d97c..68b5bd0 100644 --- a/CodeIgniter-3.1.13/application/controllers/Albums.php +++ b/CodeIgniter-3.1.13/application/controllers/Albums.php @@ -33,36 +33,18 @@ class Albums extends CI_Controller { $data['genres'] = $this->model_music->getGenres(); $data['artists'] = $this->model_music->getArtists(); - include 'temporaire.php'; - if($logged == true){ - $this->load->view('layout/header_dark'); - $this->load->view('layout/header_logged_dark'); - $this->load->view('albums_list', $data); - $this->load->view('layout/footer_dark'); - } else { - $this->load->view('layout/header_dark'); - $this->load->view('layout/header_not_logged_dark'); - $this->load->view('albums_list', $data); - $this->load->view('layout/footer_dark'); - } + $this->load->view('layout/header_dark'); + $this->load->view('albums_list', $data); + $this->load->view('layout/footer_dark'); } public function view($id){ $album = $this->model_music->get_album_by_id($id); $data['album'] = $album; - include 'temporaire.php'; - if($logged == true){ - $this->load->view('layout/header_dark'); - $this->load->view('layout/header_logged_dark'); - $this->load->view('album_view', $data); - $this->load->view('layout/footer_dark'); - } else { - $this->load->view('layout/header_dark'); - $this->load->view('layout/header_not_logged_dark'); - $this->load->view('album_view', $data); - $this->load->view('layout/footer_dark'); - } + $this->load->view('layout/header_dark'); + $this->load->view('album_view', $data); + $this->load->view('layout/footer_dark'); } } diff --git a/CodeIgniter-3.1.13/application/controllers/Artiste.php b/CodeIgniter-3.1.13/application/controllers/Artiste.php index 11b867e..ce85aad 100644 --- a/CodeIgniter-3.1.13/application/controllers/Artiste.php +++ b/CodeIgniter-3.1.13/application/controllers/Artiste.php @@ -25,18 +25,9 @@ class Artiste extends CI_Controller { $data['albums'] = $albums; $data['mostUsedGenre'] = $mostUsedGenre; // Passer $mostUsedGenre à la vue - include 'temporaire.php'; - if($logged == true){ - $this->load->view('layout/header_dark'); - $this->load->view('layout/header_logged_dark'); - $this->load->view('artiste_details', $data); - $this->load->view('layout/footer_dark'); - } else { - $this->load->view('layout/header_dark'); - $this->load->view('layout/header_not_logged_dark'); - $this->load->view('artiste_details', $data); - $this->load->view('layout/footer_dark'); - } + $this->load->view('layout/header_dark'); + $this->load->view('artiste_details', $data); + $this->load->view('layout/footer_dark'); } else { // Gérer le cas où l'artiste n'est pas trouvé == afficher un error 404 @@ -56,18 +47,9 @@ class Artiste extends CI_Controller { $data['artists'] = $artists; $data['current_order'] = $order; - include 'temporaire.php'; - if($logged == true){ - $this->load->view('layout/header_dark'); - $this->load->view('layout/header_logged_dark'); - $this->load->view('artists_list', $data); - $this->load->view('layout/footer_dark'); - } else { - $this->load->view('layout/header_dark'); - $this->load->view('layout/header_not_logged_dark'); - $this->load->view('artists_list', $data); - $this->load->view('layout/footer_dark'); - } + $this->load->view('layout/header_dark'); + $this->load->view('artists_list', $data); + $this->load->view('layout/footer_dark'); } } ?> diff --git a/CodeIgniter-3.1.13/application/controllers/Home.php b/CodeIgniter-3.1.13/application/controllers/Home.php index 35afd61..e819135 100644 --- a/CodeIgniter-3.1.13/application/controllers/Home.php +++ b/CodeIgniter-3.1.13/application/controllers/Home.php @@ -16,19 +16,9 @@ public function index() { $data['covers'] = $this->Cover_model->get_covers(); // Charger la vue avec les données récupérées - - include 'temporaire.php'; - if($logged == true){ - $this->load->view('layout/header_dark'); - $this->load->view('layout/header_logged_dark'); - $this->load->view('accueil', $data); - $this->load->view('layout/footer_dark'); - } else { - $this->load->view('layout/header_dark'); - $this->load->view('layout/header_not_logged_dark'); - $this->load->view('accueil', $data); - $this->load->view('layout/footer_dark'); - } + $this->load->view('layout/header_dark'); + $this->load->view('accueil', $data); + $this->load->view('layout/footer_dark'); } } ?> \ No newline at end of file diff --git a/CodeIgniter-3.1.13/application/controllers/MentionsLegales.php b/CodeIgniter-3.1.13/application/controllers/MentionsLegales.php index 24c7476..d840a40 100644 --- a/CodeIgniter-3.1.13/application/controllers/MentionsLegales.php +++ b/CodeIgniter-3.1.13/application/controllers/MentionsLegales.php @@ -11,18 +11,9 @@ class MentionsLegales extends CI_Controller { public function index() { - include 'temporaire.php'; - if($logged == true){ - $this->load->view('layout/header_dark'); - $this->load->view('layout/header_logged_dark'); - $this->load->view('mentions-legals'); - $this->load->view('layout/footer_dark'); - } else { - $this->load->view('layout/header_dark'); - $this->load->view('layout/header_not_logged_dark'); - $this->load->view('mentions-legals'); - $this->load->view('layout/footer_dark'); - } + $this->load->view('layout/header_dark'); + $this->load->view('mentions-legals'); + $this->load->view('layout/footer_dark'); } } diff --git a/CodeIgniter-3.1.13/application/controllers/Musiques.php b/CodeIgniter-3.1.13/application/controllers/Musiques.php index 67d74c2..e5a2127 100644 --- a/CodeIgniter-3.1.13/application/controllers/Musiques.php +++ b/CodeIgniter-3.1.13/application/controllers/Musiques.php @@ -37,18 +37,9 @@ class Musiques extends CI_Controller { $data['sort'] = $sort; // Passer la valeur de tri à la vue // Charger la vue - include 'temporaire.php'; - if($logged == true){ - $this->load->view('layout/header_dark'); - $this->load->view('layout/header_logged_dark'); - $this->load->view('musiques_list', $data); - $this->load->view('layout/footer_dark'); - } else { - $this->load->view('layout/header_dark'); - $this->load->view('layout/header_not_logged_dark'); - $this->load->view('musiques_list', $data); - $this->load->view('layout/footer_dark'); - } + $this->load->view('layout/header_dark'); + $this->load->view('musiques_list', $data); + $this->load->view('layout/footer_dark'); } } diff --git a/CodeIgniter-3.1.13/application/controllers/Search.php b/CodeIgniter-3.1.13/application/controllers/Search.php index fa46fe9..dc097dc 100644 --- a/CodeIgniter-3.1.13/application/controllers/Search.php +++ b/CodeIgniter-3.1.13/application/controllers/Search.php @@ -25,19 +25,9 @@ class Search extends CI_Controller { $data['artistes'] = []; $data['error'] = "La requête de recherche ne peut pas être vide."; - - if($logged == true){ - $this->load->view('layout/header_dark'); - $this->load->view('layout/header_logged_dark'); - $this->load->view('search_results', $data); - $this->load->view('layout/footer_dark'); - } else { - $this->load->view('layout/header_dark'); - $this->load->view('layout/header_not_logged_dark'); - $this->load->view('search_results', $data); - $this->load->view('layout/footer_dark'); - } - return; + $this->load->view('layout/header_dark'); + $this->load->view('search_results', $data); + $this->load->view('layout/footer_dark'); } // Faire une recherche dans les musiques, les albums, les genres et les artistes @@ -53,16 +43,8 @@ class Search extends CI_Controller { $data['genres'] = $genres; $data['artistes'] = $artistes; - if($logged == true){ - $this->load->view('layout/header_dark'); - $this->load->view('layout/header_logged_dark'); - $this->load->view('search_results', $data); - $this->load->view('layout/footer_dark'); - } else { - $this->load->view('layout/header_dark'); - $this->load->view('layout/header_not_logged_dark'); - $this->load->view('search_results', $data); - $this->load->view('layout/footer_dark'); - } + $this->load->view('layout/header_dark'); + $this->load->view('search_results', $data); + $this->load->view('layout/footer_dark'); } } diff --git a/CodeIgniter-3.1.13/application/controllers/Utilisateur.php b/CodeIgniter-3.1.13/application/controllers/Utilisateur.php index cae2d04..eb522a9 100644 --- a/CodeIgniter-3.1.13/application/controllers/Utilisateur.php +++ b/CodeIgniter-3.1.13/application/controllers/Utilisateur.php @@ -5,11 +5,12 @@ class Utilisateur extends CI_Controller { public function __construct(){ parent::__construct(); - $this->load->helper(array('form', 'url')); + $this->load->helper(array('form', 'url', 'cookie')); $this->load->library(array('form_validation', 'session')); $this->load->model('Utilisateur_model'); $this->load->helper('html'); } + public function inscription(){ // Définir les règles de validation @@ -24,7 +25,6 @@ class Utilisateur extends CI_Controller { if ($this->form_validation->run() == FALSE) { // Charger la vue avec les erreurs $this->load->view('layout/header_dark'); - $this->load->view('layout/header_not_logged_dark'); $this->load->view('inscription'); $this->load->view('layout/footer_dark'); } else { @@ -43,7 +43,6 @@ class Utilisateur extends CI_Controller { } else { $data['error'] = 'Une erreur est survenue. Veuillez réessayer.'; $this->load->view('layout/header_dark'); - $this->load->view('layout/header_not_logged_dark'); $this->load->view('inscription', $data); $this->load->view('layout/footer_dark'); } @@ -58,7 +57,6 @@ class Utilisateur extends CI_Controller { if ($this->form_validation->run() == FALSE) { // Charger la vue avec les erreurs $this->load->view('layout/header_dark'); - $this->load->view('layout/header_not_logged_dark'); $this->load->view('connexion'); $this->load->view('layout/footer_dark'); } else { @@ -72,16 +70,36 @@ class Utilisateur extends CI_Controller { if ($user && password_verify($password, $user->password)) { // Connexion réussie, enregistrer l'utilisateur dans la session $this->session->set_userdata('user_id', $user->id); + // Définir un cookie pour indiquer que l'utilisateur est connecté + $cookie = array( + 'name' => 'user_logged_in', + 'value' => '1', + 'expire' => '86500', // durée de vie du cookie (1 jour) + 'secure' => TRUE + ); + $this->input->set_cookie($cookie); redirect('utilisateur/dashboard'); } else { $data['error'] = 'Email ou mot de passe incorrect.'; $this->load->view('layout/header_dark'); - $this->load->view('layout/header_logged_dark'); $this->load->view('connexion', $data); $this->load->view('layout/footer_dark'); } } } + + public function deconnexion(){ + // Détruire la session de l'utilisateur + $this->session->unset_userdata('user_id'); + $this->session->sess_destroy(); + + // Supprimer le cookie + delete_cookie('user_logged_in'); + + // Rediriger vers la page de connexion + redirect('utilisateur/connexion'); + } + public function dashboard(){ if(!$this->session->userdata('user_id')){ redirect('utilisateur/connexion'); @@ -93,12 +111,10 @@ class Utilisateur extends CI_Controller { // Charger les vues $this->load->view('layout/header_dark'); - $this->load->view('layout/header_logged_dark'); $this->load->view('dashboard', $data); $this->load->view('layout/footer_dark'); } - public function modifier(){ if(!$this->session->userdata('user_id')){ redirect('utilisateur/connexion'); @@ -127,10 +143,8 @@ class Utilisateur extends CI_Controller { $data['user'] = $this->Utilisateur_model->get_user_by_id($user_id); $this->load->view('layout/header_dark'); - $this->load->view('layout/header_logged_dark'); $this->load->view('dashboard', $data); $this->load->view('layout/footer_dark'); } } - } diff --git a/CodeIgniter-3.1.13/application/views/dashboard.php b/CodeIgniter-3.1.13/application/views/dashboard.php index 8d863ae..8e06caf 100644 --- a/CodeIgniter-3.1.13/application/views/dashboard.php +++ b/CodeIgniter-3.1.13/application/views/dashboard.php @@ -4,11 +4,11 @@ Dashboard - +
-

Bienvenue, prenom; ?>

+

Bienvenue, prenom; ?> 👋 !

diff --git a/CodeIgniter-3.1.13/application/views/layout/header_dark.php b/CodeIgniter-3.1.13/application/views/layout/header_dark.php index 19ed55d..bb3c27f 100644 --- a/CodeIgniter-3.1.13/application/views/layout/header_dark.php +++ b/CodeIgniter-3.1.13/application/views/layout/header_dark.php @@ -3,7 +3,7 @@ - + 'assets/img/Logo_ONZEUR.png', @@ -11,4 +11,16 @@ 'type'=>'image/x-icon' ))?> - \ No newline at end of file + + + + + load->view('layout/header_logged_dark'); ?> + + + load->view('layout/header_not_logged_dark'); ?> + + + + + diff --git a/CodeIgniter-3.1.13/assets/css/inscription.css b/CodeIgniter-3.1.13/assets/css/inscription.css index 7edeb49..79fb096 100644 --- a/CodeIgniter-3.1.13/assets/css/inscription.css +++ b/CodeIgniter-3.1.13/assets/css/inscription.css @@ -90,6 +90,12 @@ label { font-size: 14px; } +.success { + color: green; + margin-top: 5px; + font-size: 15px; +} + .user-info { width: 100%; border-collapse: collapse;