diff --git a/api/src/Controllers/LoginController.php b/api/src/Controllers/LoginController.php index c9084007..c3749cee 100755 --- a/api/src/Controllers/LoginController.php +++ b/api/src/Controllers/LoginController.php @@ -291,6 +291,9 @@ class LoginController { // Récupérer l'ID de l'opération active (première opération retournée) $activeOperationId = $operations[0]['id']; + // Mettre à jour l'operation_id dans la session + Session::setOperationId($activeOperationId); + // Récupérer ope_user_id pour l'utilisateur connecté et l'opération active $opeUserStmt = $this->db->prepare( 'SELECT id FROM ope_users WHERE fk_user = ? AND fk_operation = ?' @@ -1090,6 +1093,9 @@ class LoginController { $activeOperationId = $operations[0]['id']; + // Mettre à jour l'operation_id dans la session + Session::setOperationId($activeOperationId); + // Récupérer ope_user_id pour l'utilisateur connecté et l'opération active $opeUserStmt = $this->db->prepare( 'SELECT id FROM ope_users WHERE fk_user = ? AND fk_operation = ?' diff --git a/api/src/Controllers/UserController.php b/api/src/Controllers/UserController.php index d7bbea08..4328f797 100755 --- a/api/src/Controllers/UserController.php +++ b/api/src/Controllers/UserController.php @@ -503,17 +503,8 @@ class UserController { ]); $userId = $this->db->lastInsertId(); - // Récupérer l'opération active pour l'entité de l'admin créateur - $stmtActiveOpe = $this->db->prepare(' - SELECT o.id - FROM operations o - INNER JOIN users u ON u.fk_entite = o.fk_entite - WHERE u.id = ? AND o.chk_active = 1 - LIMIT 1 - '); - $stmtActiveOpe->execute([$currentUserId]); - $activeOpeData = $stmtActiveOpe->fetch(PDO::FETCH_ASSOC); - $activeOperationId = $activeOpeData ? (int)$activeOpeData['id'] : null; + // Récupérer l'opération active depuis la session (déjà récupérée lors du login) + $activeOperationId = Session::getOperationId(); $opeUserId = null; diff --git a/api/src/Core/Session.php b/api/src/Core/Session.php index 609d0e20..d84a9d45 100755 --- a/api/src/Core/Session.php +++ b/api/src/Core/Session.php @@ -62,6 +62,7 @@ class Session { $_SESSION['user_email'] = $userData['email'] ?? ''; $_SESSION['entity_id'] = $userData['fk_entite'] ?? null; $_SESSION['fk_role'] = $userData['fk_role'] ?? 1; + $_SESSION['operation_id'] = $userData['operation_id'] ?? null; $_SESSION['authenticated'] = true; $_SESSION['last_activity'] = time(); @@ -94,6 +95,14 @@ class Session { return $_SESSION['fk_role'] ?? null; } + public static function getOperationId(): ?int { + return $_SESSION['operation_id'] ?? null; + } + + public static function setOperationId(?int $operationId): void { + $_SESSION['operation_id'] = $operationId; + } + public static function requireAuth(): void { if (!self::isAuthenticated()) { // Log détaillé pour le debug