Création d'un dashboard

This commit is contained in:
stiti 2024-05-25 00:10:47 +02:00
parent d69c8fe37a
commit 3ee078d36e
8 changed files with 143 additions and 64 deletions

View File

@ -72,14 +72,65 @@ class Utilisateur extends CI_Controller {
if ($user && password_verify($password, $user->password)) { if ($user && password_verify($password, $user->password)) {
// Connexion réussie, enregistrer l'utilisateur dans la session // Connexion réussie, enregistrer l'utilisateur dans la session
$this->session->set_userdata('user_id', $user->id); $this->session->set_userdata('user_id', $user->id);
redirect('dashboard'); redirect('utilisateur/dashboard');
} else { } else {
$data['error'] = 'Email ou mot de passe incorrect.'; $data['error'] = 'Email ou mot de passe incorrect.';
$this->load->view('layout/header_dark'); $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('connexion', $data);
$this->load->view('layout/footer_dark'); $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');
}
}
} }

View File

@ -17,4 +17,14 @@ class Utilisateur_model extends CI_Model {
return $query->row(); 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);
}
} }
?>

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Connexion</title> <title>Connexion</title>
<link rel="stylesheet" href="<?php echo base_url('assets/css/connexion'); ?>"> <link rel="stylesheet" href="<?php echo base_url('assets/css/inscription'); ?>">
</head> </head>
<body> <body>
<div class="container"> <div class="container">

View File

@ -0,0 +1,64 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard</title>
<link rel="stylesheet" href="<?php echo base_url('assets/css/inscription'); ?>">
</head>
<body>
<div class="container">
<h2>Bienvenue, <?php echo $user->prenom; ?></h2>
<?php if (isset($success)): ?>
<p class="success"><?php echo $success; ?></p>
<?php endif; ?>
<?php if (isset($error)): ?>
<p class="error"><?php echo $error; ?></p>
<?php endif; ?>
<h3>Vos informations personnelles</h3>
<table class="user-info">
<tr>
<th>Prénom</th>
<td><?php echo $user->prenom; ?></td>
</tr>
<tr>
<th>Nom</th>
<td><?php echo $user->nom; ?></td>
</tr>
<tr>
<th>Email</th>
<td><?php echo $user->email; ?></td>
</tr>
</table>
<h3>Modifier vos informations</h3>
<?php echo form_open('utilisateur/modifier'); ?>
<div class="form-group">
<label for="prenom">Prénom :</label>
<input type="text" name="prenom" id="prenom" value="<?php echo set_value('prenom', $user->prenom); ?>" required>
<?php echo form_error('prenom'); ?>
</div>
<div class="form-group">
<label for="nom">Nom :</label>
<input type="text" name="nom" id="nom" value="<?php echo set_value('nom', $user->nom); ?>" required>
<?php echo form_error('nom'); ?>
</div>
<div class="form-group">
<label for="email">E-mail :</label>
<input type="email" name="email" id="email" value="<?php echo set_value('email', $user->email); ?>" required>
<?php echo form_error('email'); ?>
</div>
<button type="submit" class="btn-submit">Mettre à jour</button>
<?php echo form_close(); ?>
</div>
</body>
</html>

View File

@ -20,7 +20,7 @@
<a href="<?php echo site_url('artiste/list_artists'); ?>" class="btn-artistes">Artistes</a> <a href="<?php echo site_url('artiste/list_artists'); ?>" class="btn-artistes">Artistes</a>
<a href="<?php echo site_url('musiques'); ?>" class="btn-musiques">Musiques</a> <a href="<?php echo site_url('musiques'); ?>" class="btn-musiques">Musiques</a>
<a href="#PlaylistBIENTOT" class="btn-playlist">Mes Playlists</a> <a href="#PlaylistBIENTOT" class="btn-playlist">Mes Playlists</a>
<a href="#CompteBIENTOT" class="btn-MonCompte">Mon compte</a> <a href="<?php echo site_url('utilisateur/dashboard'); ?>" class="btn-MonCompte">Mon compte</a>
</div> </div>
</nav> </nav>
<div class="menu-toggle"> <div class="menu-toggle">

View File

@ -19,7 +19,7 @@
<a href="<?php echo site_url('albums'); ?>" class="btn-albums">Albums</a> <a href="<?php echo site_url('albums'); ?>" class="btn-albums">Albums</a>
<a href="<?php echo site_url('artiste/list_artists'); ?>" class="btn-artistes">Artistes</a> <a href="<?php echo site_url('artiste/list_artists'); ?>" class="btn-artistes">Artistes</a>
<a href="<?php echo site_url('musiques'); ?>" class="btn-musiques">Musiques</a> <a href="<?php echo site_url('musiques'); ?>" class="btn-musiques">Musiques</a>
<a href="#CONNEXIONBIENTOT" class="btn-connexion">Connexion</a> <a href="<?php echo site_url('utilisateur/connexion'); ?>" class="btn-connexion">Connexion</a>
<a href="<?php echo site_url('utilisateur/inscription'); ?>" class="btn-inscription">Inscription</a> <a href="<?php echo site_url('utilisateur/inscription'); ?>" class="btn-inscription">Inscription</a>
</div> </div>
</nav> </nav>

View File

@ -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;
}

View File

@ -89,3 +89,14 @@ label {
margin-top: 5px; margin-top: 5px;
font-size: 14px; 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;
}