Added methods setBirthday(string|RegisteredPeerRecord $peer, int $year, int $month, int $day): void and deleteBirthday(string|RegisteredPeerRecord $peer): void to \Socialbox\Managers > RegisteredPeerManager
This commit is contained in:
parent
20fa093463
commit
c0de6ce006
3 changed files with 142 additions and 0 deletions
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Socialbox\Classes\StandardMethods;
|
||||
|
||||
use Exception;
|
||||
use Socialbox\Abstracts\Method;
|
||||
use Socialbox\Classes\Validator;
|
||||
use Socialbox\Enums\Flags\SessionFlags;
|
||||
use Socialbox\Enums\StandardError;
|
||||
use Socialbox\Exceptions\StandardException;
|
||||
use Socialbox\Interfaces\SerializableInterface;
|
||||
use Socialbox\Managers\RegisteredPeerManager;
|
||||
use Socialbox\Managers\SessionManager;
|
||||
use Socialbox\Objects\ClientRequest;
|
||||
use Socialbox\Objects\RpcRequest;
|
||||
|
||||
class SettingsSetBirthday extends Method
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||
{
|
||||
if(!$rpcRequest->containsParameter('email_address'))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, "Missing 'email_address' parameter");
|
||||
}
|
||||
|
||||
if(!Validator::validateEmailAddress($rpcRequest->getParameter('email_address')))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, "Invalid 'email_address' parameter, must be a valid email address");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Set the password
|
||||
RegisteredPeerManager::updateEmailAddress($request->getPeer(), $rpcRequest->getParameter('email_address'));
|
||||
|
||||
// Check & update the session flow
|
||||
SessionManager::updateFlow($request->getSession(), [SessionFlags::SET_EMAIL]);
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
throw new StandardException('Failed to set email address due to an internal exception', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||
}
|
||||
|
||||
return $rpcRequest->produceResponse(true);
|
||||
}
|
||||
}
|
|
@ -55,4 +55,17 @@
|
|||
{
|
||||
return preg_match("/^\+[0-9]{1,15}$/", $phoneNumber) === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates whether the given date is a valid gregorian calendar date.
|
||||
*
|
||||
* @param int $month The month component of the date (1 through 12).
|
||||
* @param int $day The day component of the date.
|
||||
* @param int $year The year component of the date.
|
||||
* @return bool Returns true if the provided date is valid, otherwise false.
|
||||
*/
|
||||
public static function validateDate(int $month, int $day, int $year): bool
|
||||
{
|
||||
return checkdate($month, $day, $year);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue