Modifications page d'accueil
This commit is contained in:
parent
96c879d0f9
commit
baae5280b9
application
@ -49,6 +49,11 @@ defined('BASEPATH') OR exit('No direct script access allowed');
|
|||||||
| Examples: my-controller/index -> my_controller/index
|
| Examples: my-controller/index -> my_controller/index
|
||||||
| my-controller/my-method -> my_controller/my_method
|
| my-controller/my-method -> my_controller/my_method
|
||||||
*/
|
*/
|
||||||
$route['default_controller'] = 'welcome';
|
$route['default_controller'] = 'Albums';
|
||||||
$route['404_override'] = '';
|
$route['404_override'] = '';
|
||||||
$route['translate_uri_dashes'] = FALSE;
|
$route['translate_uri_dashes'] = FALSE;
|
||||||
|
|
||||||
|
$route['albums'] = 'albums/index';
|
||||||
|
$route['connect/login'] = 'connect/login';
|
||||||
|
$route['connect/logout'] = 'connect/logout';
|
||||||
|
$route['connect/create'] = 'connect/create';
|
||||||
|
@ -7,12 +7,12 @@ class Connect extends CI_Controller {
|
|||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->load->model('User_model');
|
$this->load->model('User_model');
|
||||||
$this->load->library('session');
|
$this->load->library(['form_validation', 'session']);
|
||||||
|
$this->load->helper(['url', 'form']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create()
|
public function create()
|
||||||
{
|
{
|
||||||
$this->load->library('form_validation');
|
|
||||||
$this->form_validation->set_rules('nom', 'Nom', 'required');
|
$this->form_validation->set_rules('nom', 'Nom', 'required');
|
||||||
$this->form_validation->set_rules('prenom', 'Pré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('email', 'Adresse mail', 'valid_email|required');
|
||||||
@ -32,12 +32,11 @@ class Connect extends CI_Controller {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if ($this->User_model->create_user($data)) {
|
if ($this->User_model->create_user($data)) {
|
||||||
// Redirect to a success page or login page
|
|
||||||
redirect('connect/login');
|
redirect('connect/login');
|
||||||
} else {
|
} else {
|
||||||
// Handle error
|
$data['error'] = 'Erreur lors de la création du compte. Veuillez réessayer.';
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
$this->load->view('create');
|
$this->load->view('create', $data);
|
||||||
$this->load->view('layout/footer');
|
$this->load->view('layout/footer');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,10 +44,9 @@ class Connect extends CI_Controller {
|
|||||||
|
|
||||||
public function login()
|
public function login()
|
||||||
{
|
{
|
||||||
$this->load->library('form_validation');
|
|
||||||
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
|
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
|
||||||
$this->form_validation->set_rules('password', 'Password', 'required');
|
$this->form_validation->set_rules('password', 'Password', 'required');
|
||||||
|
|
||||||
if ($this->form_validation->run() === FALSE) {
|
if ($this->form_validation->run() === FALSE) {
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
$this->load->view('login');
|
$this->load->view('login');
|
||||||
@ -56,18 +54,20 @@ class Connect extends CI_Controller {
|
|||||||
} else {
|
} else {
|
||||||
$email = $this->input->post('email');
|
$email = $this->input->post('email');
|
||||||
$password = $this->input->post('password');
|
$password = $this->input->post('password');
|
||||||
|
|
||||||
$user = $this->User_model->get_user_by_email($email);
|
$user = $this->User_model->get_user_by_email($email);
|
||||||
|
|
||||||
if ($user && password_verify($password, $user['password'])) {
|
if ($user && password_verify($password, $user['password'])) {
|
||||||
// Set session data and redirect to a protected page
|
$this->session->set_userdata([
|
||||||
$this->session->set_userdata('user_id', $user['id']);
|
'user_id' => $user['id'],
|
||||||
|
'email' => $user['email'],
|
||||||
|
'logged_in' => TRUE
|
||||||
|
]);
|
||||||
redirect('albums');
|
redirect('albums');
|
||||||
} else {
|
} else {
|
||||||
// Handle login error
|
|
||||||
$data['error'] = 'Adresse email ou mot de passe incorrect';
|
$data['error'] = 'Adresse email ou mot de passe incorrect';
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
$this->load->view('login', $data); // Passer le message d'erreur à la vue
|
$this->load->view('login', $data);
|
||||||
$this->load->view('layout/footer');
|
$this->load->view('layout/footer');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,9 +75,7 @@ class Connect extends CI_Controller {
|
|||||||
|
|
||||||
public function logout()
|
public function logout()
|
||||||
{
|
{
|
||||||
$this->session->unset_userdata('user_id');
|
$this->session->sess_destroy();
|
||||||
redirect('connect/login');
|
redirect('connect/login');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,6 @@ class Welcome extends CI_Controller {
|
|||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$this->load->view('welcome_message');
|
redirect('albums/index');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class User_model extends CI_Model {
|
class User_model extends CI_Model {
|
||||||
|
|
||||||
public function __construct()
|
public function __construct() {
|
||||||
{
|
|
||||||
$this->load->database();
|
$this->load->database();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create_user($data)
|
public function get_user_by_email($email) {
|
||||||
{
|
$query = $this->db->get_where('users', ['email' => $email]);
|
||||||
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();
|
return $query->row_array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function create_user($data) {
|
||||||
|
return $this->db->insert('users', $data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -1,21 +1,28 @@
|
|||||||
<?=validation_errors(); ?>
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Login</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<?= validation_errors(); ?>
|
||||||
|
|
||||||
<?php if (isset($error)): ?>
|
<?php if (isset($error)): ?>
|
||||||
<p style="color: red;"><?= $error ?></p>
|
<p style="color: red;"><?= $error ?></p>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?=form_open('connect/login')?>
|
<?= form_open('connect/login') ?>
|
||||||
<!-- Grid -->
|
<!-- Grid -->
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<label for="email">Adresse mail</label>
|
<label for="email">Adresse mail</label>
|
||||||
<input type="email" id="email" name="email" placeholder="Email" value="<?=set_value('email')?>" required>
|
<input type="email" id="email" name="email" placeholder="Email" value="<?= set_value('email') ?>" required>
|
||||||
|
|
||||||
<label for="password">Password</label>
|
<label for="password">Password</label>
|
||||||
<input type="password" id="password" name="password" placeholder="Password" value="<?=set_value('password')?>" required>
|
<input type="password" id="password" name="password" placeholder="Password" value="<?= set_value('password') ?>" required>
|
||||||
</div>
|
</div>
|
||||||
<!-- Button -->
|
<!-- Button -->
|
||||||
<button type="submit">Submit</button>
|
<button type="submit">Submit</button>
|
||||||
|
|
||||||
<?=anchor('connect/create', "Pas de compte ? Créez-en un !");?>
|
<?= anchor('connect/create', "Pas de compte ? Créez-en un !"); ?>
|
||||||
|
</form>
|
||||||
</form>
|
</body>
|
||||||
|
</html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user