Made message signing in Cryptography use SHA512 as the message content for... #1
2 changed files with 64 additions and 1 deletions
|
@ -0,0 +1,59 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Socialbox\Classes\StandardMethods;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use Socialbox\Abstracts\Method;
|
||||||
|
use Socialbox\Enums\StandardError;
|
||||||
|
use Socialbox\Enums\Types\ContactRelationshipType;
|
||||||
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
|
use Socialbox\Exceptions\StandardException;
|
||||||
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
use Socialbox\Managers\ContactManager;
|
||||||
|
use Socialbox\Objects\ClientRequest;
|
||||||
|
use Socialbox\Objects\PeerAddress;
|
||||||
|
use Socialbox\Objects\RpcRequest;
|
||||||
|
use Socialbox\Socialbox;
|
||||||
|
|
||||||
|
class AddressBookDeleteContact extends Method
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||||
|
{
|
||||||
|
if(!$rpcRequest->containsParameter('peer'))
|
||||||
|
{
|
||||||
|
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, 'Missing required \'peer\' parameter');
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$address = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
|
||||||
|
}
|
||||||
|
catch(InvalidArgumentException $e)
|
||||||
|
{
|
||||||
|
throw new StandardException('Invalid peer address', StandardError::RPC_INVALID_ARGUMENTS, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Check if the contact already exists
|
||||||
|
$peer = $request->getPeer();
|
||||||
|
if(!ContactManager::isContact($peer, $address))
|
||||||
|
{
|
||||||
|
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Contact does not exist');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the contact
|
||||||
|
ContactManager::deleteContact($peer, $address);
|
||||||
|
}
|
||||||
|
catch (DatabaseOperationException $e)
|
||||||
|
{
|
||||||
|
throw new StandardException('Failed to remove contact', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return success
|
||||||
|
return $rpcRequest->produceResponse(true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,6 +7,7 @@
|
||||||
use Socialbox\Classes\StandardMethods\AcceptPrivacyPolicy;
|
use Socialbox\Classes\StandardMethods\AcceptPrivacyPolicy;
|
||||||
use Socialbox\Classes\StandardMethods\AcceptTermsOfService;
|
use Socialbox\Classes\StandardMethods\AcceptTermsOfService;
|
||||||
use Socialbox\Classes\StandardMethods\AddressBookAddContact;
|
use Socialbox\Classes\StandardMethods\AddressBookAddContact;
|
||||||
|
use Socialbox\Classes\StandardMethods\AddressBookDeleteContact;
|
||||||
use Socialbox\Classes\StandardMethods\Authenticate;
|
use Socialbox\Classes\StandardMethods\Authenticate;
|
||||||
use Socialbox\Classes\StandardMethods\GetAllowedMethods;
|
use Socialbox\Classes\StandardMethods\GetAllowedMethods;
|
||||||
use Socialbox\Classes\StandardMethods\GetCommunityGuidelines;
|
use Socialbox\Classes\StandardMethods\GetCommunityGuidelines;
|
||||||
|
@ -98,6 +99,7 @@
|
||||||
case SETTINGS_GET_SIGNING_KEYS = 'settingsGetSigningKeys';
|
case SETTINGS_GET_SIGNING_KEYS = 'settingsGetSigningKeys';
|
||||||
|
|
||||||
case ADDRESS_BOOK_ADD_CONTACT = 'addressBookAddContact';
|
case ADDRESS_BOOK_ADD_CONTACT = 'addressBookAddContact';
|
||||||
|
case ADDRESS_BOOK_DELETE_CONTACT = 'addressBookDeleteContact';
|
||||||
|
|
||||||
case AUTHENTICATE = 'authenticate';
|
case AUTHENTICATE = 'authenticate';
|
||||||
case RESOLVE_PEER = 'resolvePeer';
|
case RESOLVE_PEER = 'resolvePeer';
|
||||||
|
@ -149,6 +151,7 @@
|
||||||
self::SETTINGS_GET_SIGNING_KEYS => SettingsGetSigningKeys::execute($request, $rpcRequest),
|
self::SETTINGS_GET_SIGNING_KEYS => SettingsGetSigningKeys::execute($request, $rpcRequest),
|
||||||
|
|
||||||
self::ADDRESS_BOOK_ADD_CONTACT => AddressBookAddContact::execute($request, $rpcRequest),
|
self::ADDRESS_BOOK_ADD_CONTACT => AddressBookAddContact::execute($request, $rpcRequest),
|
||||||
|
self::ADDRESS_BOOK_DELETE_CONTACT => AddressBookDeleteContact::execute($request, $rpcRequest),
|
||||||
|
|
||||||
self::AUTHENTICATE => Authenticate::execute($request, $rpcRequest),
|
self::AUTHENTICATE => Authenticate::execute($request, $rpcRequest),
|
||||||
self::RESOLVE_PEER => ResolvePeer::execute($request, $rpcRequest),
|
self::RESOLVE_PEER => ResolvePeer::execute($request, $rpcRequest),
|
||||||
|
@ -281,7 +284,8 @@
|
||||||
self::SETTINGS_SET_BIRTHDAY,
|
self::SETTINGS_SET_BIRTHDAY,
|
||||||
self::RESOLVE_PEER,
|
self::RESOLVE_PEER,
|
||||||
|
|
||||||
self::ADDRESS_BOOK_ADD_CONTACT
|
self::ADDRESS_BOOK_ADD_CONTACT,
|
||||||
|
self::ADDRESS_BOOK_DELETE_CONTACT,
|
||||||
];
|
];
|
||||||
|
|
||||||
// Prevent the user from deleting their display name if it is required
|
// Prevent the user from deleting their display name if it is required
|
||||||
|
|
Loading…
Add table
Reference in a new issue