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") {
|
||||
$email = $_POST['email'];
|
||||
$password = $_POST['password'];
|
||||
|
||||
if (!empty($email) && !empty($password)) {
|
||||
$this->load->database();
|
||||
// Utilisation d'une requête préparée pour éviter les injections SQL
|
||||
$query = $this->db->query("SELECT * FROM users WHERE email = ?", array($email));
|
||||
$result = $query->row(); // Récupérer la première ligne de résultat
|
||||
|
||||
if ($result) { // Vérifier si l'utilisateur existe
|
||||
if (password_verify($password, $result->mdp)) { // Vérifier si le mot de passe est correct
|
||||
$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('url');
|
||||
$this->load->helper('form');
|
||||
if (!$this->session->userdata('user_id')) {
|
||||
redirect('connexion');
|
||||
}
|
||||
}
|
||||
|
||||
public function index(){
|
||||
|
||||
if (!$this->session->userdata('user_id')) {
|
||||
// Redirigez vers la page de connexion
|
||||
redirect('connexion');
|
||||
}
|
||||
|
||||
$userId = $this->session->userdata('user_id');
|
||||
$playlists = $this->model_music->getPlaylistsByUser($userId);
|
||||
$this->load->view('layout/header');
|
||||
@ -53,23 +53,24 @@ class Playlist extends CI_Controller {
|
||||
}
|
||||
|
||||
public function view($id) {
|
||||
|
||||
if (!$this->session->userdata('user_id')) {
|
||||
// Redirigez vers la page de connexion
|
||||
redirect('connexion');
|
||||
}
|
||||
$songs = $this->model_music->getSongsByPlaylist($id);
|
||||
$playlist = $this->model_music->getPlaylistById($id);
|
||||
if ($playlist) {
|
||||
$data['playlistName'] = $playlist->name; // Passez le nom de la playlist à la vue
|
||||
$data['songs'] = $songs;
|
||||
$data['playlistId'] = $id;
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('playlist_view', $data);
|
||||
$this->load->view('layout/footer');
|
||||
} else {
|
||||
echo "Playlist non trouvée.";
|
||||
if($this->model_music->playlistOfUser($id)){
|
||||
$songs = $this->model_music->getSongsByPlaylist($id);
|
||||
$playlist = $this->model_music->getPlaylistById($id);
|
||||
if ($playlist) {
|
||||
$data['playlistName'] = $playlist->name;
|
||||
$data['songs'] = $songs;
|
||||
$data['playlistId'] = $id;
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('playlist_view', $data);
|
||||
$this->load->view('layout/footer');
|
||||
} else {
|
||||
echo "Playlist non trouvée.";
|
||||
}
|
||||
}else{
|
||||
redirect('albums');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function add_song(){
|
||||
@ -98,10 +99,7 @@ class Playlist extends CI_Controller {
|
||||
}
|
||||
|
||||
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'));
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('choose_playlist', ['playlists' => $playlists, 'songId' => $songId]);
|
||||
@ -110,10 +108,7 @@ class Playlist extends CI_Controller {
|
||||
|
||||
|
||||
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'));
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('choix_playlist', ['playlists' => $playlists, 'albumId' => $albumId]);
|
||||
@ -142,10 +137,7 @@ public function choix_playlist($albumId) {
|
||||
}
|
||||
|
||||
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('playlist_generate');
|
||||
$this->load->view('layout/footer');
|
||||
|
@ -100,28 +100,53 @@ class Model_music extends CI_Model {
|
||||
$query = $this->db->query("SELECT * FROM genre");
|
||||
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
|
||||
$params = ["%{$query}%", "%{$query}%"];
|
||||
|
||||
if (!empty($genre)) {
|
||||
$sql .= " AND genre.id = ?";
|
||||
$params[] = $genre;
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql, $params);
|
||||
|
||||
public function playlistOfUser($id){
|
||||
$user_id = $this->session->userdata('user_id');
|
||||
$this->db->select('id');
|
||||
|
||||
$this->db->from('playlist');
|
||||
$this->db->where('userId', $user_id);
|
||||
$this->db->where('id', $id);
|
||||
|
||||
$query = $this->db->get();
|
||||
|
||||
return $query->num_rows() > 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
public function createPlaylist($name, $userId) {
|
||||
$data = array(
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<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="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>
|
||||
</form>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user