From 3ee078d36e33446bd52ff17f2324128bd790273d Mon Sep 17 00:00:00 2001 From: stiti Date: Sat, 25 May 2024 00:10:47 +0200 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation=20d'un=20dashboard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/controllers/Utilisateur.php | 57 ++++++++++++++++- .../application/models/Utilisateur_model.php | 12 +++- .../application/views/connexion.php | 2 +- .../application/views/dashboard.php | 64 +++++++++++++++++++ .../views/layout/header_logged_dark.php | 2 +- .../views/layout/header_not_logged_dark.php | 2 +- CodeIgniter-3.1.13/assets/css/connexion.css | 57 ----------------- CodeIgniter-3.1.13/assets/css/inscription.css | 11 ++++ 8 files changed, 143 insertions(+), 64 deletions(-) create mode 100644 CodeIgniter-3.1.13/application/views/dashboard.php delete mode 100644 CodeIgniter-3.1.13/assets/css/connexion.css diff --git a/CodeIgniter-3.1.13/application/controllers/Utilisateur.php b/CodeIgniter-3.1.13/application/controllers/Utilisateur.php index c07e3ae..cae2d04 100644 --- a/CodeIgniter-3.1.13/application/controllers/Utilisateur.php +++ b/CodeIgniter-3.1.13/application/controllers/Utilisateur.php @@ -72,14 +72,65 @@ 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); - redirect('dashboard'); + redirect('utilisateur/dashboard'); } else { $data['error'] = 'Email ou mot de passe incorrect.'; $this->load->view('layout/header_dark'); - $this->load->view('layout/header_not_logged_dark'); + $this->load->view('layout/header_logged_dark'); $this->load->view('connexion', $data); $this->load->view('layout/footer_dark'); } } - } + } + public function dashboard(){ + if(!$this->session->userdata('user_id')){ + redirect('utilisateur/connexion'); + } + + // Fetch les informations des utilisateurs + $user_id = $this->session->userdata('user_id'); + $data['user'] = $this->Utilisateur_model->get_user_by_id($user_id); + + // 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'); + } + + // Definition des règles + $this->form_validation->set_rules('email', 'Email', 'required|valid_email'); + $this->form_validation->set_rules('nom', 'Nom', 'required'); + $this->form_validation->set_rules('prenom', 'Prénom', 'required'); + + if ($this->form_validation->run() == FALSE) { + $this->dashboard(); + } else { + $user_id = $this->session->userdata('user_id'); + $data = array( + 'email' => $this->input->post('email'), + 'nom' => $this->input->post('nom'), + 'prenom' => $this->input->post('prenom') + ); + + if ($this->Utilisateur_model->update_user($user_id, $data)) { + $data['success'] = 'Informations mises à jour avec succès.'; + } else { + $data['error'] = 'Une erreur est survenue. Veuillez réessayer.'; + } + + $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/models/Utilisateur_model.php b/CodeIgniter-3.1.13/application/models/Utilisateur_model.php index 7736445..c261762 100644 --- a/CodeIgniter-3.1.13/application/models/Utilisateur_model.php +++ b/CodeIgniter-3.1.13/application/models/Utilisateur_model.php @@ -16,5 +16,15 @@ class Utilisateur_model extends CI_Model { $query = $this->db->get_where('utilisateur', array('email' => $email)); return $query->row(); } - + + public function get_user_by_id($id) { + $query = $this->db->get_where('utilisateur', array('id' => $id)); + return $query->row(); + } + + public function update_user($id, $data){ + $this->db->where('id', $id); + return $this->db->update('utilisateur', $data); + } } +?> diff --git a/CodeIgniter-3.1.13/application/views/connexion.php b/CodeIgniter-3.1.13/application/views/connexion.php index 4b5e0da..1ae5650 100644 --- a/CodeIgniter-3.1.13/application/views/connexion.php +++ b/CodeIgniter-3.1.13/application/views/connexion.php @@ -4,7 +4,7 @@ Connexion - +
diff --git a/CodeIgniter-3.1.13/application/views/dashboard.php b/CodeIgniter-3.1.13/application/views/dashboard.php new file mode 100644 index 0000000..8d863ae --- /dev/null +++ b/CodeIgniter-3.1.13/application/views/dashboard.php @@ -0,0 +1,64 @@ + + + + + + Dashboard + + + +
+

Bienvenue, prenom; ?>

+ + +

+ + + +

+ + +

Vos informations personnelles

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

Modifier vos informations

+ + + +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ + + + +
+ + diff --git a/CodeIgniter-3.1.13/application/views/layout/header_logged_dark.php b/CodeIgniter-3.1.13/application/views/layout/header_logged_dark.php index 851f0ad..8ab9636 100644 --- a/CodeIgniter-3.1.13/application/views/layout/header_logged_dark.php +++ b/CodeIgniter-3.1.13/application/views/layout/header_logged_dark.php @@ -20,7 +20,7 @@ Artistes Musiques Mes Playlists - Mon compte + Mon compte
diff --git a/CodeIgniter-3.1.13/assets/css/connexion.css b/CodeIgniter-3.1.13/assets/css/connexion.css deleted file mode 100644 index ea53e67..0000000 --- a/CodeIgniter-3.1.13/assets/css/connexion.css +++ /dev/null @@ -1,57 +0,0 @@ -body { - margin: 0; - font-family: Arial, sans-serif; -} - -.container { - max-width: 500px; - margin: 50px auto; - padding: 20px; - background-color: #fff; - border-radius: 8px; - box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); -} - -h2 { - text-align: center; - color: #333; -} - -.form-group { - margin-bottom: 20px; -} - -label { - display: block; - margin-bottom: 8px; - font-weight: bold; -} - -input[type="email"], -input[type="password"], -button { - width: 100%; - padding: 10px; - margin-bottom: 10px; - border: 1px solid #ccc; - border-radius: 4px; - box-sizing: border-box; -} - -button { - background-color: #634caf; - color: #fff; - border: none; - cursor: pointer; - transition: background-color 0.3s; -} - -button:hover { - background-color: rgb(54, 16, 119); -} - -.error { - color: red; - margin-top: 5px; - font-size: 14px; -} diff --git a/CodeIgniter-3.1.13/assets/css/inscription.css b/CodeIgniter-3.1.13/assets/css/inscription.css index f1e7c81..7edeb49 100644 --- a/CodeIgniter-3.1.13/assets/css/inscription.css +++ b/CodeIgniter-3.1.13/assets/css/inscription.css @@ -89,3 +89,14 @@ label { margin-top: 5px; font-size: 14px; } + +.user-info { + width: 100%; + border-collapse: collapse; + margin-bottom: 20px; +} + +.user-info th, .user-info td { + padding: 10px; + border: 1px solid #ccc; +} \ No newline at end of file