Ajout del'inscription, connection et deconnection avec bd

This commit is contained in:
2024-06-09 17:31:35 +02:00
parent 6ff83097b2
commit c61c485651
9 changed files with 147 additions and 67 deletions

View File

@@ -11,19 +11,14 @@ class Albums extends CI_Controller {
$this->load->helper('html');
$this->load->helper('url');
$this->load->helper('form');
$this->filter = $this->input->get('filter');
}
public function index(){
if ($this->filter == "co") {
$this->load->view('layout/header');
$this->load->view('new_user');
}else{
$albums = $this->model_music->getAlbums();
$this->load->view('layout/header');
$this->load->view('albums_list',['albums'=>$albums]);
$this->load->view('layout/footer');
}
}
}

View File

@@ -0,0 +1,46 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class ConnexionController extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper(array('url', 'html'));
$this->load->library('session');
}
public function connexion() {
$this->load->view('layout/header');
$this->load->view('connexion');
$this->load->view('layout/footer');
}
public function authentifier() {
if($_SERVER["REQUEST_METHOD"] == "POST"){
$email = $_POST['email'];
$password = $_POST['password'];
if($email != "" && $password != ""){
$this->load->database();
$query = $this->db->query("SELECT * FROM users WHERE email = '$email' AND mdp = '$password'");
$result = $query->row(); // Récupérer la première ligne de résultat
if($result){ // Vérifier si l'utilisateur existe
$this->session->set_userdata('pseudo', $result->pseudo);
redirect('../index.php');
} else {
$data['error_msg'] = "Email ou mot de passe incorrect.";
}
}
$this->load->view('layout/header');
$this->load->view('connexion', $data);
$this->load->view('layout/footer');
}
}
public function deconnexion() {
$this->session->unset_userdata('pseudo');
$this->session->sess_destroy();
redirect('../index.php');
}
}

View File

@@ -0,0 +1,47 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class InscriptionController extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper(array('url', 'html'));
}
public function inscription() {
$this->load->view('layout/header');
$this->load->view('inscription');
$this->load->view('layout/footer');
}
public function traitement() {
if(isset($_POST['ok'])){
$this->load->database();
$prenom = ucfirst(strtolower($this->input->post('prenom')));
$nom = strtoupper($this->input->post('nom'));
$pseudo = $this->input->post('pseudo');
$mdp = $this->input->post('pass');
$email = $this->input->post('email');
$data = array(
'pseudo' => $pseudo,
'nom' => $nom,
'prenom' => $prenom,
'mdp' => $mdp,
'email' => $email
);
$this->db->insert('users', $data);
$data['confirmation_message'] = "Inscription réussie ! Vous êtes maintenant inscrit.";
$this->load->view('layout/header');
$this->load->view('inscription', $data);
$this->load->view('layout/footer');
}
}
}