Add methods for deleting and updating peer information

This commit is contained in:
netkas 2025-01-04 15:32:42 -05:00
parent cb1cc5ee15
commit b04de2f2a7
5 changed files with 343 additions and 25 deletions

View file

@ -0,0 +1,39 @@
<?php
namespace Socialbox\Classes\StandardMethods;
use Exception;
use Socialbox\Abstracts\Method;
use Socialbox\Classes\Configuration;
use Socialbox\Enums\StandardError;
use Socialbox\Exceptions\StandardException;
use Socialbox\Interfaces\SerializableInterface;
use Socialbox\Managers\RegisteredPeerManager;
use Socialbox\Objects\ClientRequest;
use Socialbox\Objects\RpcRequest;
class SettingsDeleteDisplayName extends Method
{
/**
* @inheritDoc
*/
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
{
if(Configuration::getRegistrationConfiguration()->isDisplayNameRequired())
{
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'A display name is required for this server');
}
try
{
// Set the password
RegisteredPeerManager::deleteDisplayName($request->getPeer());
}
catch(Exception $e)
{
throw new StandardException('Failed to set password due to an internal exception', StandardError::INTERNAL_SERVER_ERROR, $e);
}
return $rpcRequest->produceResponse(true);
}
}

View file

@ -34,4 +34,14 @@ class Validator
return preg_match(self::USERNAME_PATTERN, $username) === 1;
}
/**
* Validates whether a given phone number conforms to the required format.
*
* @param string $phoneNumber The phone number to validate. Must start with a "+" followed by 1 to 15 digits.
* @return bool Returns true if the phone number is valid according to the format, otherwise false.
*/
public static function validatePhoneNumber(string $phoneNumber): bool
{
return preg_match("/^\+[0-9]{1,15}$/", $phoneNumber) === 1;
}
}