Refactor session handling in policy acceptance methods.

This commit is contained in:
netkas 2025-01-06 02:17:49 -05:00
parent da250d6189
commit 3a72363937
2 changed files with 12 additions and 7 deletions

View file

@ -21,7 +21,8 @@
*/ */
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface 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'); return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Community guidelines has already been accepted');
} }
@ -29,7 +30,7 @@
try try
{ {
// Check & update the session flow // Check & update the session flow
SessionManager::updateFlow($request->getSession(), [SessionFlags::VER_COMMUNITY_GUIDELINES]); SessionManager::updateFlow($session, [SessionFlags::VER_COMMUNITY_GUIDELINES]);
} }
catch (DatabaseOperationException $e) catch (DatabaseOperationException $e)
{ {

View file

@ -13,19 +13,23 @@
class AcceptPrivacyPolicy extends Method class AcceptPrivacyPolicy extends Method
{ {
/** /**
* Executes the process of accepting the privacy policy.
*
* @inheritDoc * @inheritDoc
*/ */
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface 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 try
{ {
// Remove the verification flag
SessionManager::removeFlags($request->getSessionUuid(), [SessionFlags::VER_PRIVACY_POLICY]);
// Check & update the session flow // Check & update the session flow
SessionManager::updateFlow($request->getSession()); SessionManager::updateFlow($session, [SessionFlags::VER_PRIVACY_POLICY]);
} }
catch (DatabaseOperationException $e) catch (DatabaseOperationException $e)
{ {