From 3a723639377f70abb0adb544440213070cb03033 Mon Sep 17 00:00:00 2001 From: netkas Date: Mon, 6 Jan 2025 02:17:49 -0500 Subject: [PATCH] Refactor session handling in policy acceptance methods. --- .../StandardMethods/AcceptCommunityGuidelines.php | 5 +++-- .../StandardMethods/AcceptPrivacyPolicy.php | 14 +++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Socialbox/Classes/StandardMethods/AcceptCommunityGuidelines.php b/src/Socialbox/Classes/StandardMethods/AcceptCommunityGuidelines.php index 6694bfd..0bb9370 100644 --- a/src/Socialbox/Classes/StandardMethods/AcceptCommunityGuidelines.php +++ b/src/Socialbox/Classes/StandardMethods/AcceptCommunityGuidelines.php @@ -21,7 +21,8 @@ */ public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface { - if(!$request->getSession()->flagExists(SessionFlags::VER_COMMUNITY_GUIDELINES)) + $session = $request->getSession(); + if(!$session->flagExists(SessionFlags::VER_COMMUNITY_GUIDELINES)) { return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Community guidelines has already been accepted'); } @@ -29,7 +30,7 @@ try { // Check & update the session flow - SessionManager::updateFlow($request->getSession(), [SessionFlags::VER_COMMUNITY_GUIDELINES]); + SessionManager::updateFlow($session, [SessionFlags::VER_COMMUNITY_GUIDELINES]); } catch (DatabaseOperationException $e) { diff --git a/src/Socialbox/Classes/StandardMethods/AcceptPrivacyPolicy.php b/src/Socialbox/Classes/StandardMethods/AcceptPrivacyPolicy.php index a09c5cd..feb5811 100644 --- a/src/Socialbox/Classes/StandardMethods/AcceptPrivacyPolicy.php +++ b/src/Socialbox/Classes/StandardMethods/AcceptPrivacyPolicy.php @@ -13,19 +13,23 @@ class AcceptPrivacyPolicy extends Method { - /** + * Executes the process of accepting the privacy policy. + * * @inheritDoc */ public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface { + $session = $request->getSession(); + if(!$session->flagExists(SessionFlags::VER_PRIVACY_POLICY)) + { + return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Privacy policy has already been accepted'); + } + try { - // Remove the verification flag - SessionManager::removeFlags($request->getSessionUuid(), [SessionFlags::VER_PRIVACY_POLICY]); - // Check & update the session flow - SessionManager::updateFlow($request->getSession()); + SessionManager::updateFlow($session, [SessionFlags::VER_PRIVACY_POLICY]); } catch (DatabaseOperationException $e) {