mirror of
https://grond.iut-fbleau.fr/stiti/SAE_2.02
synced 2024-11-09 21:11:40 +01:00
Ajout de la connexion
This commit is contained in:
parent
40a7dd1979
commit
761946625b
@ -16,7 +16,8 @@ class Utilisateur extends CI_Controller {
|
|||||||
$this->form_validation->set_rules('nom', 'Nom', 'required');
|
$this->form_validation->set_rules('nom', 'Nom', 'required');
|
||||||
$this->form_validation->set_rules('prenom', 'Prénom', 'required');
|
$this->form_validation->set_rules('prenom', 'Prénom', 'required');
|
||||||
$this->form_validation->set_rules('telephone', 'Téléphone', 'max_length[20]');
|
$this->form_validation->set_rules('telephone', 'Téléphone', 'max_length[20]');
|
||||||
|
$this->form_validation->set_rules('password', 'Mot de passe', 'required|min_length[6]');
|
||||||
|
|
||||||
if ($this->form_validation->run() == FALSE) {
|
if ($this->form_validation->run() == FALSE) {
|
||||||
// Charger la vue avec les erreurs
|
// Charger la vue avec les erreurs
|
||||||
$this->load->view('layout/header_not_logged_dark');
|
$this->load->view('layout/header_not_logged_dark');
|
||||||
@ -28,13 +29,14 @@ class Utilisateur extends CI_Controller {
|
|||||||
'email' => $this->input->post('email'),
|
'email' => $this->input->post('email'),
|
||||||
'nom' => $this->input->post('nom'),
|
'nom' => $this->input->post('nom'),
|
||||||
'prenom' => $this->input->post('prenom'),
|
'prenom' => $this->input->post('prenom'),
|
||||||
'telephone' => $this->input->post('telephone')
|
'telephone' => $this->input->post('telephone'),
|
||||||
|
'password' => password_hash($this->input->post('password'), PASSWORD_DEFAULT) // Hasher le mot de passe
|
||||||
);
|
);
|
||||||
|
|
||||||
// Insérer les données dans la base de données
|
// Insérer les données dans la base de données
|
||||||
if ($this->Utilisateur_model->insert_user($data)) {
|
if ($this->Utilisateur_model->insert_user($data)) {
|
||||||
$this->session->set_flashdata('success', 'Inscription réussie. Vous pouvez maintenant vous connecter.');
|
$this->session->set_flashdata('success', 'Inscription réussie. Vous pouvez maintenant vous connecter.');
|
||||||
redirect('utilisateur/inscription');
|
redirect('utilisateur/connexion');
|
||||||
} else {
|
} else {
|
||||||
$data['error'] = 'Une erreur est survenue. Veuillez réessayer.';
|
$data['error'] = 'Une erreur est survenue. Veuillez réessayer.';
|
||||||
$this->load->view('layout/header_not_logged_dark');
|
$this->load->view('layout/header_not_logged_dark');
|
||||||
@ -43,4 +45,35 @@ class Utilisateur extends CI_Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function connexion(){
|
||||||
|
// Définir les règles de validation
|
||||||
|
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
|
||||||
|
$this->form_validation->set_rules('password', 'Mot de passe', 'required');
|
||||||
|
|
||||||
|
if ($this->form_validation->run() == FALSE) {
|
||||||
|
// Charger la vue avec les erreurs
|
||||||
|
$this->load->view('layout/header_not_logged_dark');
|
||||||
|
$this->load->view('connexion');
|
||||||
|
$this->load->view('layout/footer_dark');
|
||||||
|
} else {
|
||||||
|
// Récupérer les données du formulaire
|
||||||
|
$email = $this->input->post('email');
|
||||||
|
$password = $this->input->post('password');
|
||||||
|
|
||||||
|
// Vérifier les informations d'identification dans la base de données
|
||||||
|
$user = $this->Utilisateur_model->get_user($email);
|
||||||
|
|
||||||
|
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');
|
||||||
|
} else {
|
||||||
|
$data['error'] = 'Email ou mot de passe incorrect.';
|
||||||
|
$this->load->view('layout/header_not_logged_dark');
|
||||||
|
$this->load->view('connexion', $data);
|
||||||
|
$this->load->view('layout/footer_dark');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,4 +11,10 @@ class Utilisateur_model extends CI_Model {
|
|||||||
public function insert_user($data){
|
public function insert_user($data){
|
||||||
return $this->db->insert('utilisateur', $data);
|
return $this->db->insert('utilisateur', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function get_user($email) {
|
||||||
|
$query = $this->db->get_where('utilisateur', array('email' => $email));
|
||||||
|
return $query->row();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
36
CodeIgniter-3.1.13/application/views/connexion.php
Normal file
36
CodeIgniter-3.1.13/application/views/connexion.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Connexion</title>
|
||||||
|
<link rel="stylesheet" href="<?php echo base_url('assets/css/connexion'); ?>">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h2>Connexion</h2>
|
||||||
|
|
||||||
|
<?php if (isset($error)): ?>
|
||||||
|
<p class="error"><?php echo $error; ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php echo form_open('utilisateur/connexion'); ?>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="email">Email :</label>
|
||||||
|
<input type="email" name="email" id="email" value="<?php echo set_value('email'); ?>" required>
|
||||||
|
<?php echo form_error('email'); ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="password">Mot de passe :</label>
|
||||||
|
<input type="password" name="password" id="password" required>
|
||||||
|
<?php echo form_error('password'); ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" class="btn-submit">Connexion</button>
|
||||||
|
|
||||||
|
<?php echo form_close(); ?>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -21,6 +21,20 @@
|
|||||||
<input type="email" name="email" id="email" value="<?php echo set_value('email'); ?>" required>
|
<input type="email" name="email" id="email" value="<?php echo set_value('email'); ?>" required>
|
||||||
<?php echo form_error('email'); ?>
|
<?php echo form_error('email'); ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="password">Mot de passe :</label>
|
||||||
|
<input type="password" name="password" id="password" required>
|
||||||
|
<?php echo form_error('password'); ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="confirm_password">Confirmer le mot de passe :</label>
|
||||||
|
<input type="password" name="confirm_password" id="confirm_password" required>
|
||||||
|
<?php echo form_error('confirm_password'); ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="nom">Nom :</label>
|
<label for="nom">Nom :</label>
|
||||||
|
57
CodeIgniter-3.1.13/assets/css/connexion.css
Normal file
57
CodeIgniter-3.1.13/assets/css/connexion.css
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
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;
|
||||||
|
}
|
@ -31,7 +31,8 @@ label {
|
|||||||
#nom,
|
#nom,
|
||||||
#prenom,
|
#prenom,
|
||||||
#telephone,
|
#telephone,
|
||||||
button {
|
#password,
|
||||||
|
#confirm_password {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
|
Loading…
Reference in New Issue
Block a user