connexion presque finie
This commit is contained in:
parent
8911872fe7
commit
96c879d0f9
application
config
controllers
models
views
@ -58,7 +58,7 @@ $autoload['packages'] = array();
|
|||||||
|
|
|
|
||||||
| $autoload['libraries'] = array('user_agent' => 'ua');
|
| $autoload['libraries'] = array('user_agent' => 'ua');
|
||||||
*/
|
*/
|
||||||
$autoload['libraries'] = array();
|
$autoload['libraries'] = array('session');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
| -------------------------------------------------------------------
|
| -------------------------------------------------------------------
|
||||||
|
@ -387,7 +387,7 @@ $config['sess_driver'] = 'files';
|
|||||||
$config['sess_cookie_name'] = 'ci_session';
|
$config['sess_cookie_name'] = 'ci_session';
|
||||||
$config['sess_samesite'] = 'Lax';
|
$config['sess_samesite'] = 'Lax';
|
||||||
$config['sess_expiration'] = 7200;
|
$config['sess_expiration'] = 7200;
|
||||||
$config['sess_save_path'] = NULL;
|
$config['sess_save_path'] = '/tmp';
|
||||||
$config['sess_match_ip'] = FALSE;
|
$config['sess_match_ip'] = FALSE;
|
||||||
$config['sess_time_to_update'] = 300;
|
$config['sess_time_to_update'] = 300;
|
||||||
$config['sess_regenerate_destroy'] = FALSE;
|
$config['sess_regenerate_destroy'] = FALSE;
|
||||||
|
83
application/controllers/Connect.php
Normal file
83
application/controllers/Connect.php
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||||
|
|
||||||
|
class Connect extends CI_Controller {
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->load->model('User_model');
|
||||||
|
$this->load->library('session');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
$this->load->library('form_validation');
|
||||||
|
$this->form_validation->set_rules('nom', 'Nom', 'required');
|
||||||
|
$this->form_validation->set_rules('prenom', 'Prénom', 'required');
|
||||||
|
$this->form_validation->set_rules('email', 'Adresse mail', 'valid_email|required');
|
||||||
|
$this->form_validation->set_rules('password', 'Password', 'min_length[5]|required');
|
||||||
|
$this->form_validation->set_rules('cpassword', 'Confirmation Password', 'required|matches[password]');
|
||||||
|
|
||||||
|
if ($this->form_validation->run() === FALSE) {
|
||||||
|
$this->load->view('layout/header');
|
||||||
|
$this->load->view('create');
|
||||||
|
$this->load->view('layout/footer');
|
||||||
|
} else {
|
||||||
|
$data = array(
|
||||||
|
'nom' => $this->input->post('nom'),
|
||||||
|
'prenom' => $this->input->post('prenom'),
|
||||||
|
'email' => $this->input->post('email'),
|
||||||
|
'password' => password_hash($this->input->post('password'), PASSWORD_DEFAULT)
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($this->User_model->create_user($data)) {
|
||||||
|
// Redirect to a success page or login page
|
||||||
|
redirect('connect/login');
|
||||||
|
} else {
|
||||||
|
// Handle error
|
||||||
|
$this->load->view('layout/header');
|
||||||
|
$this->load->view('create');
|
||||||
|
$this->load->view('layout/footer');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function login()
|
||||||
|
{
|
||||||
|
$this->load->library('form_validation');
|
||||||
|
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
|
||||||
|
$this->form_validation->set_rules('password', 'Password', 'required');
|
||||||
|
|
||||||
|
if ($this->form_validation->run() === FALSE) {
|
||||||
|
$this->load->view('layout/header');
|
||||||
|
$this->load->view('login');
|
||||||
|
$this->load->view('layout/footer');
|
||||||
|
} else {
|
||||||
|
$email = $this->input->post('email');
|
||||||
|
$password = $this->input->post('password');
|
||||||
|
|
||||||
|
$user = $this->User_model->get_user_by_email($email);
|
||||||
|
|
||||||
|
if ($user && password_verify($password, $user['password'])) {
|
||||||
|
// Set session data and redirect to a protected page
|
||||||
|
$this->session->set_userdata('user_id', $user['id']);
|
||||||
|
redirect('albums');
|
||||||
|
} else {
|
||||||
|
// Handle login error
|
||||||
|
$data['error'] = 'Adresse email ou mot de passe incorrect';
|
||||||
|
$this->load->view('layout/header');
|
||||||
|
$this->load->view('login', $data); // Passer le message d'erreur à la vue
|
||||||
|
$this->load->view('layout/footer');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function logout()
|
||||||
|
{
|
||||||
|
$this->session->unset_userdata('user_id');
|
||||||
|
redirect('connect/login');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
21
application/models/User_model.php
Normal file
21
application/models/User_model.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
class User_model extends CI_Model {
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->load->database();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create_user($data)
|
||||||
|
{
|
||||||
|
return $this->db->insert('user', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_user_by_email($email)
|
||||||
|
{
|
||||||
|
$this->db->where('email', $email);
|
||||||
|
$query = $this->db->get('user');
|
||||||
|
return $query->row_array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
32
application/views/create.php
Normal file
32
application/views/create.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?=validation_errors(); ?>
|
||||||
|
<?=form_open('connect/create')?>
|
||||||
|
<!-- Grid -->
|
||||||
|
<div class="grid">
|
||||||
|
|
||||||
|
<label for="prenom">
|
||||||
|
Prénom
|
||||||
|
<input type="text" id="prenom" name="prenom" placeholder="Prénom" value="<?=set_value('prenom')?>" required>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label for="nom">
|
||||||
|
Nom
|
||||||
|
<input type="text" id="nom" name="nom" placeholder="Nom" value="<?=set_value('nom')?>" required>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label for="email">Adresse mail</label>
|
||||||
|
<input type="email" id="email" name="email" placeholder="Email" value="<?=set_value('email')?>" required>
|
||||||
|
|
||||||
|
<div class="grid">
|
||||||
|
<label for="password">Password
|
||||||
|
<input type="password" id="password" name="password" placeholder="Password" value="<?=set_value('password')?>" required>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label for="cpassword">Confirmation password
|
||||||
|
<input type="password" id="cpassword" name="cpassword" placeholder="Confirmation Password" value="<?=set_value('cpassword')?>" required>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Button -->
|
||||||
|
<button type="submit">Submit</button>
|
||||||
|
</form>
|
@ -2,7 +2,7 @@
|
|||||||
<html lang="en" class="has-navbar-fixed-top">
|
<html lang="en" class="has-navbar-fixed-top">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<title>MUSIC APP</title>
|
<title>Dix heures</title>
|
||||||
<link
|
<link
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
|
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
|
||||||
@ -13,13 +13,19 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main class='container'>
|
<main class='container'>
|
||||||
<nav>
|
<nav>
|
||||||
<ul>
|
<ul>
|
||||||
<li><strong>Music APP</strong></li>
|
<li><strong>Dix heures</strong></li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul>
|
<ul>
|
||||||
<li><?=anchor('albums','Albums');?></li>
|
<li><?=anchor('albums','Albums');?></li>
|
||||||
<li><?=anchor('artistes','Artistes');?></li>
|
<li><?=anchor('artistes','Artistes');?></li>
|
||||||
<li><?=anchor('playlist','Playlist');?></li>
|
<li><?=anchor('playlist','Playlist');?></li>
|
||||||
</ul>
|
<?php if ($this->session->userdata('user_id')): ?>
|
||||||
</nav>
|
<li><?=anchor('connect/logout','Déconnexion');?></li>
|
||||||
|
<?php else: ?>
|
||||||
|
<li><?=anchor('connect/login','Connexion');?></li>
|
||||||
|
<?php endif; ?>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<html lang="en" class="has-navbar-fixed-top">
|
<html lang="en" class="has-navbar-fixed-top">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<title>MUSIC APP</title>
|
<title>Dix heures</title>
|
||||||
<link
|
<link
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
|
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
|
||||||
@ -15,11 +15,12 @@
|
|||||||
<main class='container'>
|
<main class='container'>
|
||||||
<nav>
|
<nav>
|
||||||
<ul>
|
<ul>
|
||||||
<li><strong>Music APP</strong></li>
|
<li><strong>Dix heures</strong></li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul>
|
<ul>
|
||||||
<li><?=anchor('albums','Albums');?></li>
|
<li><?=anchor('albums','Albums');?></li>
|
||||||
<li><?=anchor('artistes','Artistes');?></li>
|
<li><?=anchor('artistes','Artistes');?></li>
|
||||||
<li><?=anchor('playlist','Playlist');?></li>
|
<li><?=anchor('playlist','Playlist');?></li>
|
||||||
|
<li><?=anchor('connect','Connexion');?></li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
21
application/views/login.php
Normal file
21
application/views/login.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?=validation_errors(); ?>
|
||||||
|
|
||||||
|
<?php if (isset($error)): ?>
|
||||||
|
<p style="color: red;"><?= $error ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?=form_open('connect/login')?>
|
||||||
|
<!-- Grid -->
|
||||||
|
<div class="grid">
|
||||||
|
<label for="email">Adresse mail</label>
|
||||||
|
<input type="email" id="email" name="email" placeholder="Email" value="<?=set_value('email')?>" required>
|
||||||
|
|
||||||
|
<label for="password">Password</label>
|
||||||
|
<input type="password" id="password" name="password" placeholder="Password" value="<?=set_value('password')?>" required>
|
||||||
|
</div>
|
||||||
|
<!-- Button -->
|
||||||
|
<button type="submit">Submit</button>
|
||||||
|
|
||||||
|
<?=anchor('connect/create', "Pas de compte ? Créez-en un !");?>
|
||||||
|
|
||||||
|
</form>
|
29
application/views/logout.php
Normal file
29
application/views/logout.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||||
|
?>
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en" class="has-navbar-fixed-top">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<title>Dix heures</title>
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"/>
|
||||||
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
|
||||||
|
<?=link_tag('assets/style.css')?>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main class='container'>
|
||||||
|
<nav>
|
||||||
|
<ul>
|
||||||
|
<li><strong>Dix heures</strong></li>
|
||||||
|
</ul>
|
||||||
|
<ul>
|
||||||
|
<li><?=anchor('albums','Albums');?></li>
|
||||||
|
<li><?=anchor('artistes','Artistes');?></li>
|
||||||
|
<li><?=anchor('playlist','Playlist');?></li>
|
||||||
|
<li><?=anchor('connect/login','Connexion');?></li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
<p>Vous êtes déconnecté.</p>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user