diff --git a/controllers/auth_ctrl2.php b/controllers/auth_ctrl2.php index 875b914..00ddfc7 100644 --- a/controllers/auth_ctrl2.php +++ b/controllers/auth_ctrl2.php @@ -22,7 +22,21 @@ function verify_login_ctrl(?string $route) { 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.'; diff --git a/controllers/auth_ctrl2.php~ b/controllers/auth_ctrl2.php~ index 22bf620..875b914 100644 --- a/controllers/auth_ctrl2.php~ +++ b/controllers/auth_ctrl2.php~ @@ -1,11 +1,9 @@ prepare($req); - $prep->bindValue(':id', $id); + $prep->bindValue(':login', $login); $prep->execute(); $auth = $prep->fetch(PDO::FETCH_ASSOC); $prep->closeCursor(); diff --git a/models/user_crud.php~ b/models/user_crud.php~ new file mode 100644 index 0000000..7d36bc9 --- /dev/null +++ b/models/user_crud.php~ @@ -0,0 +1,16 @@ +prepare($req); + $prep->bindValue(':login', $login); + $prep->execute(); + $auth = $prep->fetch(PDO::FETCH_ASSOC); + $prep->closeCursor(); + return $auth; + } + \ No newline at end of file