Made message signing in Cryptography use SHA512 as the message content for... #1

Closed
netkas wants to merge 421 commits from master into dev
2 changed files with 61 additions and 0 deletions
Showing only changes of commit 2656becd25 - Show all commits

View file

@ -0,0 +1,50 @@
<?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
SettingsSetEmailAddress 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);
}
}

View file

@ -18,6 +18,17 @@ class Validator
return preg_match(self::PEER_ADDRESS_PATTERN, $address) === 1; return preg_match(self::PEER_ADDRESS_PATTERN, $address) === 1;
} }
/**
* Checks if the provided email address is in a valid email format.
*
* @param string $emailAddress The email address to be validated.
* @return bool Returns true if the email address is valid, otherwise false.
*/
public static function validateEmailAddress(string $emailAddress): bool
{
return filter_var($emailAddress, FILTER_VALIDATE_EMAIL) !== false;
}
/** /**
* Validates a username * Validates a username
* *