From 5089f0cd338bac69a288a65be812c00e105a3f61 Mon Sep 17 00:00:00 2001 From: gallego Date: Mon, 10 Jun 2024 11:16:43 +0200 Subject: [PATCH] inscription connexion --- ci/application/config/autoload.php | 2 +- ci/application/config/config.php | 4 +- ci/application/config/routes.php | 1 + ci/application/controllers/Albums.php | 16 ++- ci/application/controllers/Connexion.php | 51 ++++++++++ ci/application/controllers/Deconnexion.php | 15 +++ ci/application/controllers/Enregistrer.php | 33 +++++++ ci/application/controllers/connexion.php | 14 --- ci/application/models/Model_music.php | 108 ++++++++++++++++++--- ci/application/views/Enregistrement.php | 6 ++ ci/application/views/GenreFilter.php | 13 +++ ci/application/views/SignUp.php | 6 ++ ci/application/views/layout/header.php | 4 +- ci/application/views/login.php | 5 + 14 files changed, 247 insertions(+), 31 deletions(-) create mode 100644 ci/application/controllers/Connexion.php create mode 100644 ci/application/controllers/Deconnexion.php create mode 100644 ci/application/controllers/Enregistrer.php delete mode 100644 ci/application/controllers/connexion.php create mode 100644 ci/application/views/Enregistrement.php create mode 100644 ci/application/views/GenreFilter.php create mode 100644 ci/application/views/SignUp.php create mode 100644 ci/application/views/login.php diff --git a/ci/application/config/autoload.php b/ci/application/config/autoload.php index 47a3ba2..a45e72b 100644 --- a/ci/application/config/autoload.php +++ b/ci/application/config/autoload.php @@ -58,7 +58,7 @@ $autoload['packages'] = array(); | | $autoload['libraries'] = array('user_agent' => 'ua'); */ -$autoload['libraries'] = array(); +$autoload['libraries'] = array('session'); /* | ------------------------------------------------------------------- diff --git a/ci/application/config/config.php b/ci/application/config/config.php index 45c8d4f..fdddfcb 100644 --- a/ci/application/config/config.php +++ b/ci/application/config/config.php @@ -127,7 +127,7 @@ $config['subclass_prefix'] = 'MY_'; | package auto-loader script in application/vendor/autoload.php. | | $config['composer_autoload'] = TRUE; -| +|fig.p | Or if you have your vendor/ directory located somewhere else, you | can opt to set a specific path as well: | @@ -387,7 +387,7 @@ $config['sess_driver'] = 'files'; $config['sess_cookie_name'] = 'ci_session'; $config['sess_samesite'] = 'Lax'; $config['sess_expiration'] = 7200; -$config['sess_save_path'] = NULL; +$config['sess_save_path'] = '/tmp'; $config['sess_match_ip'] = FALSE; $config['sess_time_to_update'] = 300; $config['sess_regenerate_destroy'] = FALSE; diff --git a/ci/application/config/routes.php b/ci/application/config/routes.php index e8e2296..d7093e1 100644 --- a/ci/application/config/routes.php +++ b/ci/application/config/routes.php @@ -49,6 +49,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); | Examples: my-controller/index -> my_controller/index | my-controller/my-method -> my_controller/my_method */ +$route['Connexion/login'] ='Connexion/login'; $route['default_controller'] = 'welcome'; $route['404_override'] = ''; $route['translate_uri_dashes'] = FALSE; diff --git a/ci/application/controllers/Albums.php b/ci/application/controllers/Albums.php index ca5e760..03e505f 100644 --- a/ci/application/controllers/Albums.php +++ b/ci/application/controllers/Albums.php @@ -9,11 +9,25 @@ class Albums extends CI_Controller { } public function index(){ - $albums = $this->model_music->getAlbums(); + $genre = $this->model_music->getGenre(); + $albums = $this->model_music->getAlbums($genre); $playlists = $this->model_music->getPlaylist(); $this->load->view('layout/header'); $this->load->view('albums_list', ['albums' => $albums, 'playlists' => $playlists]); $this->load->view('layout/footer'); + + $selectedGenre = '0'; + $search = ''; + if ($_SERVER["REQUEST_METHOD"] == "POST") { + if(isset($_POST['Genre'])){ + $selectedGenre = $_POST['Genre']; + } + } + if ($_SERVER["REQUEST_METHOD"] == "POST") { + if(isset($_POST['recherche'])){ + $search = $_POST['recherche']; + } + } } public function view($album_id){ diff --git a/ci/application/controllers/Connexion.php b/ci/application/controllers/Connexion.php new file mode 100644 index 0000000..3a2962e --- /dev/null +++ b/ci/application/controllers/Connexion.php @@ -0,0 +1,51 @@ +load->model('model_music'); + } + public function index(){ + $this->load->view('layout/connexion.php'); + } + +}*/ + +defined('BASEPATH') OR exit('No direct script access allowed'); + +class Connexion extends CI_Controller{ + + public function __construct(){ + parent ::__construct(); + $this->load->model('model_music'); + } + public function index(){ + //$this->load->view('layout/header'); + $this->load->view('login'); + //$this->load->view('layout/footer'); + } + public function login() { + + $login = ''; + $password = ''; + if ($_SERVER["REQUEST_METHOD"] == "POST") { + if(isset($_POST['login']) && isset($_POST['password'])){ + $login = $_POST['login']; + $password = $_POST['password']; + } + } + $result = $this->model_music->getLogin($login,$password); +if (count($result) > 0) { + $this->session->set_userdata('logged', true); + $this->load->view('layout/header'); + redirect('albums'); +} else { + $this->load->view('layout/header'); + $this->load->view('login'); + $this->load->view('layout/footer'); + echo "Invalid login or password"; +} +} +} diff --git a/ci/application/controllers/Deconnexion.php b/ci/application/controllers/Deconnexion.php new file mode 100644 index 0000000..24858a8 --- /dev/null +++ b/ci/application/controllers/Deconnexion.php @@ -0,0 +1,15 @@ +load->model('model_music'); + } + +public function index() { + $this->session->unset_userdata('logged'); + $this->session->sess_destroy(); + redirect('albums'); + } +} \ No newline at end of file diff --git a/ci/application/controllers/Enregistrer.php b/ci/application/controllers/Enregistrer.php new file mode 100644 index 0000000..d5f2a40 --- /dev/null +++ b/ci/application/controllers/Enregistrer.php @@ -0,0 +1,33 @@ +load->model('model_music'); + } + public function index(){ + //$this->load->view('layout/header'); + $this->load->view('SignUp'); + //$this->load->view('layout/footer'); + } + public function SignUp() { + $pseudo = ''; + $login = ''; + $password = ''; + if ($_SERVER["REQUEST_METHOD"] == "POST") { + if(isset($_POST['login']) && isset($_POST['password']) && isset($_POST['pseudo'])){ + $pseudo = $_POST['pseudo']; + $login = $_POST['login']; + $password = $_POST['password']; + } + } + $this->model_music->SignUp($pseudo,$login,$password); + $this->session->set_userdata('logged', true); + $this->load->view('layout/header'); + redirect('albums'); +} +} + +?> \ No newline at end of file diff --git a/ci/application/controllers/connexion.php b/ci/application/controllers/connexion.php deleted file mode 100644 index a7cc2be..0000000 --- a/ci/application/controllers/connexion.php +++ /dev/null @@ -1,14 +0,0 @@ -load->model('model_music'); - } - public function index(){ - $this->load->view('layout/connexion'); - } - -} diff --git a/ci/application/models/Model_music.php b/ci/application/models/Model_music.php index edd5f26..cf1a795 100644 --- a/ci/application/models/Model_music.php +++ b/ci/application/models/Model_music.php @@ -5,19 +5,33 @@ class Model_music extends CI_Model { $this->load->database(); } - public function getAlbums(){ - $query = $this->db->query( - "SELECT album.name,album.id,year,artist.name as artistName, genre.name as genreName,jpeg - FROM album - JOIN artist ON album.artistid = artist.id - JOIN genre ON genre.id = album.genreid - JOIN cover ON cover.id = album.coverid - ORDER BY year - " - ); - return $query->result(); + public function getAlbums($selectedGenre) { + if ($selectedGenre == '0') { + $query = $this->db->query( + "SELECT album.name, album.id, year, artist.name as artistName, genre.name as genreName, jpeg + FROM album + JOIN artist ON album.artistid = artist.id + JOIN genre ON genre.id = album.genreid + JOIN cover ON cover.id = album.coverid + ORDER BY year" + ); + } else { + $query = $this->db->query( + "SELECT album.name, album.id, year, artist.name as artistName, genre.name as genreName, jpeg + FROM album + JOIN artist ON album.artistid = artist.id + JOIN genre ON genre.id = album.genreid + JOIN cover ON cover.id = album.coverid + WHERE album.genreId = ? + ORDER BY year", + array($selectedGenre) + ); + } + + return $query->result(); } + public function getArtists(){ $query = $this->db->query( "SELECT artist.id, artist.name @@ -87,6 +101,15 @@ class Model_music extends CI_Model { return $query->result(); } + public function getGenre(){ + $query = $this->db->query( + "SELECT genre.id,genre.name + FROM genre + " + ); + return $query->result(); + } + public function getAlbumsOfArtist($artist_id){ $query = $this->db->query( "SELECT album.name, album.id, album.year, genre.name as genreName, cover.jpeg @@ -100,6 +123,69 @@ class Model_music extends CI_Model { return $query->result(); } + public function getLogin($login,$password){ + $query = $this->db->query( + "SELECT * + FROM Login + WHERE mail = '$login' AND MotDePasse = '$password'" + ); + return $query->result(); + } + public function SignUp($pseudo,$login,$password){ + $query = $this->db->query( + "INSERT INTO `Login`(`pseudo`, `mail`, `MotDePasse`) + VALUES ('$pseudo','$login','$password')" + ); + } + public function searchAlbums($search,$selectedGenre){ + if($search == '' AND $selectedGenre == '0'){ + $query = $this->db->query( + "SELECT album.name,album.id,year,artist.name as artistName, genre.name as genreName,jpeg + FROM album + JOIN artist ON album.artistid = artist.id + JOIN genre ON genre.id = album.genreid + JOIN cover ON cover.id = album.coverid + ORDER BY year + ", + ); + }elseif($search == ''){ + $query = $this->db->query( + "SELECT album.name,album.id,year,artist.name as artistName, genre.name as genreName,jpeg + FROM album + JOIN artist ON album.artistid = artist.id + JOIN genre ON genre.id = album.genreid + JOIN cover ON cover.id = album.coverid + WHERE album.genreId = $selectedGenre + ORDER BY year + ", + ); + }elseif($selectedGenre == '0' AND $search !=''){ + $query = $this->db->query( + "SELECT album.name,album.id,year,artist.name as artistName, genre.name as genreName,jpeg + FROM album + JOIN artist ON album.artistid = artist.id + JOIN genre ON genre.id = album.genreid + JOIN cover ON cover.id = album.coverid + WHERE album.name LIKE '%$search%' + ORDER BY year + ", + ); + } + else{ + $query = $this->db->query( + "SELECT album.name,album.id,year,artist.name as artistName, genre.name as genreName,jpeg + FROM album + JOIN artist ON album.artistid = artist.id + JOIN genre ON genre.id = album.genreid + JOIN cover ON cover.id = album.coverid + WHERE album.name LIKE '%$search%' AND album.genreId = $selectedGenre + ORDER BY year + ", + ); + } + return $query->result(); + } + public function addSongToPlaylist($songName, $playlistId){ $query = $this->db->query( "INSERT INTO SongPlaylist (id, name) VALUES (?, ?)", diff --git a/ci/application/views/Enregistrement.php b/ci/application/views/Enregistrement.php new file mode 100644 index 0000000..5a56f6c --- /dev/null +++ b/ci/application/views/Enregistrement.php @@ -0,0 +1,6 @@ +
+ + + + +
\ No newline at end of file diff --git a/ci/application/views/GenreFilter.php b/ci/application/views/GenreFilter.php new file mode 100644 index 0000000..fc010cb --- /dev/null +++ b/ci/application/views/GenreFilter.php @@ -0,0 +1,13 @@ +
+ "; + echo ""; + foreach($genre as $genre) { + echo ""; + } + echo ""; +echo""; + echo""; + ?> + +
diff --git a/ci/application/views/SignUp.php b/ci/application/views/SignUp.php new file mode 100644 index 0000000..5a56f6c --- /dev/null +++ b/ci/application/views/SignUp.php @@ -0,0 +1,6 @@ +
+ + + + +
\ No newline at end of file diff --git a/ci/application/views/layout/header.php b/ci/application/views/layout/header.php index 0c6adfb..bcdab3f 100644 --- a/ci/application/views/layout/header.php +++ b/ci/application/views/layout/header.php @@ -38,8 +38,8 @@
- Connexion - S'inscrire + >Connexion + >S'inscrire
diff --git a/ci/application/views/login.php b/ci/application/views/login.php new file mode 100644 index 0000000..da5ad75 --- /dev/null +++ b/ci/application/views/login.php @@ -0,0 +1,5 @@ +
+ + + +
\ No newline at end of file