diff --git a/controllers/auth_ctrl2.php b/controllers/auth_ctrl2.php index 00ddfc7..9e94da3 100644 --- a/controllers/auth_ctrl2.php +++ b/controllers/auth_ctrl2.php @@ -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'); @@ -23,35 +22,33 @@ function verify_login_ctrl(?string $route) { $_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; - } -} + header('Location: index.php?route=' . $route); + } else { + switch ($user['type']) { + case 'admin': + header('Location: index.php?route=admin'); + break; + 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(); setcookie(session_name(), '', time() - 3600, '/'); require('views/welcome_view.php'); -} +} \ No newline at end of file diff --git a/controllers/auth_ctrl2.php~ b/controllers/auth_ctrl2.php~ index 875b914..783e336 100644 --- a/controllers/auth_ctrl2.php~ +++ b/controllers/auth_ctrl2.php~ @@ -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']; - header('Location: index.php?route=' . $route); + 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.';