finition authentification

This commit is contained in:
Poty Thomas 2026-06-10 19:25:57 +02:00
parent 5df73b3ac0
commit 0c349e7aed
2 changed files with 34 additions and 19 deletions

View file

@ -10,7 +10,6 @@ function login_ctrl() {
login_form_ctrl($ask_route);
}
}
function verify_login_ctrl(?string $route) {
require('models/connection.php');
require('models/user_crud.php');
@ -24,31 +23,29 @@ function verify_login_ctrl(?string $route) {
$_SESSION['role'] = $user['type'];
if ($route) {
header('Location: index.php?route=' . $route);
} else {
} else {
switch ($user['type']) {
case 'admin':
header('Location: index.php?route=admin');
break;
case 'lecteur':
case 'administration':
header('Location: index.php?route=operations');
break;
default:
header('Location: index.php');
break;
}
}
}
exit;
} else {
echo 'Erreur d\'authentification.';
exit;
}
}
function login_form_ctrl(?string $route) {
require('views/login_views.php');
login_form_view($route);
}
function logout_ctrl() {
session_unset();
session_destroy();

View file

@ -18,11 +18,29 @@ function verify_login_ctrl(?string $route) {
$passwd = isset($_POST['password']) ? $_POST['password'] : '';
$c = connection();
$user = recuperation_auth($c, $login);
var_dump($user);
var_dump(password_verify($passwd, $user['passwd'] ?? ''));
exit;
if ($user && password_verify($passwd, $user['passwd'])) {
session_regenerate_id(true);
$_SESSION['login'] = $user['login'];
$_SESSION['role'] = $user['type'];
if ($route) {
header('Location: index.php?route=' . $route);
} else {
switch ($user['type']) {
case 'admin':
header('Location: index.php?route=admin');
break;
case 'lecteur':
header('Location: index.php?route=operations');
break;
default:
header('Location: index.php');
break;
}
}
exit;
} else {
echo 'Erreur d\'authentification.';