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

View file

@ -18,11 +18,29 @@ function verify_login_ctrl(?string $route) {
$passwd = isset($_POST['password']) ? $_POST['password'] : ''; $passwd = isset($_POST['password']) ? $_POST['password'] : '';
$c = connection(); $c = connection();
$user = recuperation_auth($c, $login); $user = recuperation_auth($c, $login);
var_dump($user);
var_dump(password_verify($passwd, $user['passwd'] ?? ''));
exit;
if ($user && password_verify($passwd, $user['passwd'])) { if ($user && password_verify($passwd, $user['passwd'])) {
session_regenerate_id(true); session_regenerate_id(true);
$_SESSION['login'] = $user['login']; $_SESSION['login'] = $user['login'];
$_SESSION['role'] = $user['type']; $_SESSION['role'] = $user['type'];
if ($route) {
header('Location: index.php?route=' . $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; exit;
} else { } else {
echo 'Erreur d\'authentification.'; echo 'Erreur d\'authentification.';