From 585ff4681090ebdd7db9809c8fad0732c028fc96 Mon Sep 17 00:00:00 2001 From: netkas Date: Mon, 6 Jan 2025 15:14:04 -0500 Subject: [PATCH] Added the method SettingsSetBirthday --- .../StandardMethods/SettingsSetBirthday.php | 28 ++++++++++++++----- .../Managers/RegisteredPeerManager.php | 4 +-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/Socialbox/Classes/StandardMethods/SettingsSetBirthday.php b/src/Socialbox/Classes/StandardMethods/SettingsSetBirthday.php index 1d48313..9af21b4 100644 --- a/src/Socialbox/Classes/StandardMethods/SettingsSetBirthday.php +++ b/src/Socialbox/Classes/StandardMethods/SettingsSetBirthday.php @@ -21,27 +21,41 @@ */ public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface { - if(!$rpcRequest->containsParameter('email_address')) + if(!$rpcRequest->containsParameter('month')) { - return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, "Missing 'email_address' parameter"); + return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, "Missing 'month' parameter"); } - if(!Validator::validateEmailAddress($rpcRequest->getParameter('email_address'))) + if(!$rpcRequest->containsParameter('day')) { - return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, "Invalid 'email_address' parameter, must be a valid email address"); + return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, "Missing 'day' parameter"); + } + + if(!$rpcRequest->containsParameter('year')) + { + return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, "Missing 'year' parameter"); + } + + $month = $rpcRequest->getParameter('month'); + $day = $rpcRequest->getParameter('day'); + $year = $rpcRequest->getParameter('year'); + + if(!Validator::validateDate($month, $day, $year)) + { + return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, "Invalid date provided, must be a valid gregorian calender date."); } try { // Set the password - RegisteredPeerManager::updateEmailAddress($request->getPeer(), $rpcRequest->getParameter('email_address')); + RegisteredPeerManager::updateBirthday($request->getPeer(), $month, $day, $year); // Check & update the session flow - SessionManager::updateFlow($request->getSession(), [SessionFlags::SET_EMAIL]); + SessionManager::updateFlow($request->getSession(), [SessionFlags::SET_BIRTHDAY]); } catch(Exception $e) { - throw new StandardException('Failed to set email address due to an internal exception', StandardError::INTERNAL_SERVER_ERROR, $e); + throw new StandardException('Failed to set birthday due to an internal exception', StandardError::INTERNAL_SERVER_ERROR, $e); } return $rpcRequest->produceResponse(true); diff --git a/src/Socialbox/Managers/RegisteredPeerManager.php b/src/Socialbox/Managers/RegisteredPeerManager.php index 7054c0c..1838226 100644 --- a/src/Socialbox/Managers/RegisteredPeerManager.php +++ b/src/Socialbox/Managers/RegisteredPeerManager.php @@ -676,14 +676,14 @@ * Sets the birthday of a registered peer record based on the provided date components. * * @param string|RegisteredPeerRecord $peer The unique identifier of the peer or an instance of RegisteredPeerRecord. - * @param int $year The year component of the birthday. * @param int $month The month component of the birthday. * @param int $day The day component of the birthday. + * @param int $year The year component of the birthday. * @return void * @throws InvalidArgumentException If the peer is external or the provided date is invalid. * @throws DatabaseOperationException If there is an error during the database operation. */ - public static function setBirthday(string|RegisteredPeerRecord $peer, int $year, int $month, int $day): void + public static function updateBirthday(string|RegisteredPeerRecord $peer, int $month, int $day, int $year): void { if(is_string($peer)) {