Add support for deleting display pictures
This commit is contained in:
parent
85814913e4
commit
2082225fb7
4 changed files with 65 additions and 9 deletions
|
@ -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 SettingsDeleteDisplayPicture extends Method
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||
{
|
||||
if(Configuration::getRegistrationConfiguration()->isDisplayPictureRequired())
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'A display picture is required for this server');
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Set the password
|
||||
RegisteredPeerManager::deleteDisplayPicture($request->getPeer());
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
throw new StandardException('Failed to update display picture: ' . $e->getMessage(), StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||
}
|
||||
|
||||
return $rpcRequest->produceResponse(true);
|
||||
}
|
||||
}
|
|
@ -34,8 +34,7 @@
|
|||
|
||||
try
|
||||
{
|
||||
$decodedImage = base64_decode($rpcRequest->getParameter('image'));
|
||||
|
||||
$decodedImage = @base64_decode($rpcRequest->getParameter('image'));
|
||||
if($decodedImage === false)
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::RPC_BAD_REQUEST, "Failed to decode JPEG image base64 data");
|
||||
|
@ -53,11 +52,11 @@
|
|||
// Set the password
|
||||
RegisteredPeerManager::updateDisplayPicture($request->getPeer(), $sanitizedImage);
|
||||
|
||||
// Remove the SET_DISPLAY_PICTURE flag
|
||||
SessionManager::removeFlags($request->getSessionUuid(), [SessionFlags::SET_DISPLAY_PICTURE]);
|
||||
|
||||
// Check & update the session flow
|
||||
SessionManager::updateFlow($request->getSession());
|
||||
if($request->getSession()->flagExists(SessionFlags::SET_DISPLAY_PICTURE))
|
||||
{
|
||||
SessionManager::updateFlow($request->getSession(), [SessionFlags::SET_DISPLAY_PICTURE]);
|
||||
}
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue