From 1108711eb730a35c7b9f3720a4bfc808994f9438 Mon Sep 17 00:00:00 2001 From: netkas Date: Mon, 23 Dec 2024 19:07:01 -0500 Subject: [PATCH] Refactor session flow management for captcha and password. --- .../StandardMethods/SettingsSetPassword.php | 18 +++--------------- .../VerificationAnswerImageCaptcha.php | 16 +--------------- 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/src/Socialbox/Classes/StandardMethods/SettingsSetPassword.php b/src/Socialbox/Classes/StandardMethods/SettingsSetPassword.php index 7269f15..8241343 100644 --- a/src/Socialbox/Classes/StandardMethods/SettingsSetPassword.php +++ b/src/Socialbox/Classes/StandardMethods/SettingsSetPassword.php @@ -50,27 +50,15 @@ // Remove the SET_PASSWORD flag SessionManager::removeFlags($request->getSessionUuid(), [SessionFlags::SET_PASSWORD]); + + // Check & update the session flow + SessionManager::updateFlow($request->getSession()); } catch(Exception $e) { throw new StandardException('Failed to set password due to an internal exception', StandardError::INTERNAL_SERVER_ERROR, $e); } - // Check if all registration flags are removed - if(SessionFlags::isComplete($request->getSession()->getFlags())) - { - // Set the session as authenticated - try - { - SessionManager::setAuthenticated($request->getSessionUuid(), true); - SessionManager::removeFlags($request->getSessionUuid(), [SessionFlags::REGISTRATION_REQUIRED, SessionFlags::AUTHENTICATION_REQUIRED]); - } - catch (DatabaseOperationException $e) - { - throw new StandardException('Failed to update session due to an internal exception', StandardError::INTERNAL_SERVER_ERROR, $e); - } - } - return $rpcRequest->produceResponse(true); } } \ No newline at end of file diff --git a/src/Socialbox/Classes/StandardMethods/VerificationAnswerImageCaptcha.php b/src/Socialbox/Classes/StandardMethods/VerificationAnswerImageCaptcha.php index 790dee9..67b5027 100644 --- a/src/Socialbox/Classes/StandardMethods/VerificationAnswerImageCaptcha.php +++ b/src/Socialbox/Classes/StandardMethods/VerificationAnswerImageCaptcha.php @@ -47,6 +47,7 @@ if($result) { SessionManager::removeFlags($request->getSessionUuid(), [SessionFlags::VER_IMAGE_CAPTCHA]); + SessionManager::updateFlow($session); } } catch (DatabaseOperationException $e) @@ -54,21 +55,6 @@ throw new StandardException("There was an unexpected error while trying to answer the captcha", StandardError::INTERNAL_SERVER_ERROR, $e); } - // Check if all registration flags are removed - if(SessionFlags::isComplete($request->getSession()->getFlags())) - { - // Set the session as authenticated - try - { - SessionManager::setAuthenticated($request->getSessionUuid(), true); - SessionManager::removeFlags($request->getSessionUuid(), [SessionFlags::REGISTRATION_REQUIRED, SessionFlags::AUTHENTICATION_REQUIRED]); - } - catch (DatabaseOperationException $e) - { - return $rpcRequest->produceError(StandardError::INTERNAL_SERVER_ERROR, $e); - } - } - return $rpcRequest->produceResponse($result); } } \ No newline at end of file