Merge branch 'main' of grond.iut-fbleau.fr:keraudre/SAE_DEV2.2_2024
This commit is contained in:
commit
1daf85e84b
codeigniter/application
@ -20,11 +20,13 @@ class ConnexionController extends CI_Controller {
|
|||||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
$email = $_POST['email'];
|
$email = $_POST['email'];
|
||||||
$password = $_POST['password'];
|
$password = $_POST['password'];
|
||||||
|
|
||||||
if (!empty($email) && !empty($password)) {
|
if (!empty($email) && !empty($password)) {
|
||||||
$this->load->database();
|
$this->load->database();
|
||||||
// Utilisation d'une requête préparée pour éviter les injections SQL
|
// Utilisation d'une requête préparée pour éviter les injections SQL
|
||||||
$query = $this->db->query("SELECT * FROM users WHERE email = ?", array($email));
|
$query = $this->db->query("SELECT * FROM users WHERE email = ?", array($email));
|
||||||
$result = $query->row(); // Récupérer la première ligne de résultat
|
$result = $query->row(); // Récupérer la première ligne de résultat
|
||||||
|
|
||||||
if ($result) { // Vérifier si l'utilisateur existe
|
if ($result) { // Vérifier si l'utilisateur existe
|
||||||
if (password_verify($password, $result->mdp)) { // Vérifier si le mot de passe est correct
|
if (password_verify($password, $result->mdp)) { // Vérifier si le mot de passe est correct
|
||||||
$this->session->set_userdata('user_id', $result->id);
|
$this->session->set_userdata('user_id', $result->id);
|
||||||
|
@ -1,48 +0,0 @@
|
|||||||
<?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('connexion');
|
|
||||||
$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');
|
|
||||||
$mdpcrypte = password_hash($mdp, PASSWORD_DEFAULT);
|
|
||||||
$email = $this->input->post('email');
|
|
||||||
|
|
||||||
$data = array(
|
|
||||||
'pseudo' => $pseudo,
|
|
||||||
'nom' => $nom,
|
|
||||||
'prenom' => $prenom,
|
|
||||||
'mdp' => $mdpcrypte,
|
|
||||||
'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('connexion', $data);
|
|
||||||
$this->load->view('layout/footer');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -9,14 +9,14 @@ class Playlist extends CI_Controller {
|
|||||||
$this->load->helper('html');
|
$this->load->helper('html');
|
||||||
$this->load->helper('url');
|
$this->load->helper('url');
|
||||||
$this->load->helper('form');
|
$this->load->helper('form');
|
||||||
|
if (!$this->session->userdata('user_id')) {
|
||||||
|
redirect('connexion');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index(){
|
public function index(){
|
||||||
|
|
||||||
if (!$this->session->userdata('user_id')) {
|
|
||||||
// Redirigez vers la page de connexion
|
|
||||||
redirect('connexion');
|
|
||||||
}
|
|
||||||
$userId = $this->session->userdata('user_id');
|
$userId = $this->session->userdata('user_id');
|
||||||
$playlists = $this->model_music->getPlaylistsByUser($userId);
|
$playlists = $this->model_music->getPlaylistsByUser($userId);
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
@ -53,15 +53,11 @@ class Playlist extends CI_Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function view($id) {
|
public function view($id) {
|
||||||
|
if($this->model_music->playlistOfUser($id)){
|
||||||
if (!$this->session->userdata('user_id')) {
|
|
||||||
// Redirigez vers la page de connexion
|
|
||||||
redirect('connexion');
|
|
||||||
}
|
|
||||||
$songs = $this->model_music->getSongsByPlaylist($id);
|
$songs = $this->model_music->getSongsByPlaylist($id);
|
||||||
$playlist = $this->model_music->getPlaylistById($id);
|
$playlist = $this->model_music->getPlaylistById($id);
|
||||||
if ($playlist) {
|
if ($playlist) {
|
||||||
$data['playlistName'] = $playlist->name; // Passez le nom de la playlist à la vue
|
$data['playlistName'] = $playlist->name;
|
||||||
$data['songs'] = $songs;
|
$data['songs'] = $songs;
|
||||||
$data['playlistId'] = $id;
|
$data['playlistId'] = $id;
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
@ -70,6 +66,11 @@ class Playlist extends CI_Controller {
|
|||||||
} else {
|
} else {
|
||||||
echo "Playlist non trouvée.";
|
echo "Playlist non trouvée.";
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
redirect('albums');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add_song(){
|
public function add_song(){
|
||||||
@ -98,10 +99,7 @@ class Playlist extends CI_Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function choose_playlist($songId) {
|
public function choose_playlist($songId) {
|
||||||
if (!$this->session->userdata('user_id')) {
|
|
||||||
// Redirigez vers la page de connexion
|
|
||||||
redirect('connexion');
|
|
||||||
}
|
|
||||||
$playlists = $this->model_music->getPlaylistsByUser($this->session->userdata('user_id'));
|
$playlists = $this->model_music->getPlaylistsByUser($this->session->userdata('user_id'));
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
$this->load->view('choose_playlist', ['playlists' => $playlists, 'songId' => $songId]);
|
$this->load->view('choose_playlist', ['playlists' => $playlists, 'songId' => $songId]);
|
||||||
@ -110,10 +108,7 @@ class Playlist extends CI_Controller {
|
|||||||
|
|
||||||
|
|
||||||
public function choix_playlist($albumId) {
|
public function choix_playlist($albumId) {
|
||||||
if (!$this->session->userdata('user_id')) {
|
|
||||||
// Redirigez vers la page de connexion
|
|
||||||
redirect('connexion');
|
|
||||||
}
|
|
||||||
$playlists = $this->model_music->getPlaylistsByUser($this->session->userdata('user_id'));
|
$playlists = $this->model_music->getPlaylistsByUser($this->session->userdata('user_id'));
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
$this->load->view('choix_playlist', ['playlists' => $playlists, 'albumId' => $albumId]);
|
$this->load->view('choix_playlist', ['playlists' => $playlists, 'albumId' => $albumId]);
|
||||||
@ -142,10 +137,7 @@ public function choix_playlist($albumId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function generate(){
|
public function generate(){
|
||||||
if (!$this->session->userdata('user_id')) {
|
|
||||||
// Redirigez vers la page de connexion
|
|
||||||
redirect('connexion');
|
|
||||||
}
|
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
$this->load->view('playlist_generate');
|
$this->load->view('playlist_generate');
|
||||||
$this->load->view('layout/footer');
|
$this->load->view('layout/footer');
|
||||||
|
@ -101,28 +101,53 @@ class Model_music extends CI_Model {
|
|||||||
return $query->result();
|
return $query->result();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function searchAlbums($query, $genre){
|
|
||||||
$sql = "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 ? OR artist.name LIKE ?
|
|
||||||
ORDER BY album.id ASC";
|
|
||||||
|
|
||||||
// Paramètres pour les conditions de recherche
|
public function playlistOfUser($id){
|
||||||
$params = ["%{$query}%", "%{$query}%"];
|
$user_id = $this->session->userdata('user_id');
|
||||||
|
$this->db->select('id');
|
||||||
|
|
||||||
if (!empty($genre)) {
|
$this->db->from('playlist');
|
||||||
$sql .= " AND genre.id = ?";
|
$this->db->where('userId', $user_id);
|
||||||
$params[] = $genre;
|
$this->db->where('id', $id);
|
||||||
|
|
||||||
|
$query = $this->db->get();
|
||||||
|
|
||||||
|
return $query->num_rows() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = $this->db->query($sql, $params);
|
|
||||||
|
|
||||||
|
public function searchAlbums($query, $genre) {
|
||||||
|
// Sélection des colonnes
|
||||||
|
$this->db->select('album.name, album.id, year, artist.name as artistName, genre.name as genreName, jpeg');
|
||||||
|
|
||||||
|
// Tables et jointures
|
||||||
|
$this->db->from('album');
|
||||||
|
$this->db->join('artist', 'album.artistid = artist.id');
|
||||||
|
$this->db->join('genre', 'genre.id = album.genreid');
|
||||||
|
$this->db->join('cover', 'cover.id = album.coverid');
|
||||||
|
|
||||||
|
// Conditions de recherche
|
||||||
|
$this->db->group_start();
|
||||||
|
$this->db->like('album.name', $query);
|
||||||
|
$this->db->or_like('artist.name', $query);
|
||||||
|
$this->db->group_end();
|
||||||
|
|
||||||
|
// Condition supplémentaire par genre si spécifié
|
||||||
|
if (!empty($genre)) {
|
||||||
|
$this->db->where('genre.id', $genre);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tri par défaut
|
||||||
|
$this->db->order_by('album.id', 'ASC');
|
||||||
|
|
||||||
|
// Exécution de la requête
|
||||||
|
$query = $this->db->get();
|
||||||
|
|
||||||
|
// Renvoi des résultats
|
||||||
return $query->result();
|
return $query->result();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function createPlaylist($name, $userId) {
|
public function createPlaylist($name, $userId) {
|
||||||
$data = array(
|
$data = array(
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<form action="<?= site_url('playlist/generate_random'); ?>" method="post" class="generate-playlist-form">
|
<form action="<?= site_url('playlist/generate_random'); ?>" method="post" class="generate-playlist-form">
|
||||||
<input type="text" name="playlistName" placeholder="Nom de la playlist" required>
|
<input type="text" name="playlistName" placeholder="Nom de la playlist" required>
|
||||||
<input type="number" name="numSongs" placeholder="Nombre de chansons" required>
|
<input type="number" min="0" max="1000" name="numSongs" placeholder="Nombre de chansons" required>
|
||||||
<button type="submit">Générer</button>
|
<button type="submit">Générer</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user