diff --git a/src/Socialbox/Classes/StandardMethods/SettingsDeleteDisplayPicture.php b/src/Socialbox/Classes/StandardMethods/SettingsDeleteDisplayPicture.php new file mode 100644 index 0000000..7e86818 --- /dev/null +++ b/src/Socialbox/Classes/StandardMethods/SettingsDeleteDisplayPicture.php @@ -0,0 +1,39 @@ +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); + } + } \ No newline at end of file diff --git a/src/Socialbox/Classes/StandardMethods/SettingsSetDisplayPicture.php b/src/Socialbox/Classes/StandardMethods/SettingsSetDisplayPicture.php index e79b2ce..e709a23 100644 --- a/src/Socialbox/Classes/StandardMethods/SettingsSetDisplayPicture.php +++ b/src/Socialbox/Classes/StandardMethods/SettingsSetDisplayPicture.php @@ -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) { diff --git a/src/Socialbox/Enums/StandardMethods.php b/src/Socialbox/Enums/StandardMethods.php index 1f33ef5..a6b8b12 100644 --- a/src/Socialbox/Enums/StandardMethods.php +++ b/src/Socialbox/Enums/StandardMethods.php @@ -13,9 +13,11 @@ use Socialbox\Classes\StandardMethods\Ping; use Socialbox\Classes\StandardMethods\SettingsAddSigningKey; use Socialbox\Classes\StandardMethods\SettingsDeleteDisplayName; + use Socialbox\Classes\StandardMethods\SettingsDeleteDisplayPicture; use Socialbox\Classes\StandardMethods\SettingsDeletePassword; use Socialbox\Classes\StandardMethods\SettingsGetSigningKeys; use Socialbox\Classes\StandardMethods\SettingsSetDisplayName; + use Socialbox\Classes\StandardMethods\SettingsSetDisplayPicture; use Socialbox\Classes\StandardMethods\SettingsSetPassword; use Socialbox\Classes\StandardMethods\SettingsUpdatePassword; use Socialbox\Classes\StandardMethods\VerificationAnswerImageCaptcha; @@ -63,6 +65,7 @@ case SETTINGS_SET_DISPLAY_NAME = 'settingsSetDisplayName'; case SETTINGS_DELETE_DISPLAY_NAME = 'settingsDeleteDisplayName'; case SETTINGS_SET_DISPLAY_PICTURE = 'settingsSetDisplayPicture'; + case SETTINGS_DELETE_DISPLAY_PICTURE = 'settingsDeleteDisplayPicture'; case SETTINGS_SET_EMAIL = 'settingsSetEmail'; case SETTINGS_SET_PHONE = 'settingsSetPhone'; case SETTINGS_SET_BIRTHDAY = 'settingsSetBirthday'; @@ -100,6 +103,8 @@ self::SETTINGS_DELETE_PASSWORD => SettingsDeletePassword::execute($request, $rpcRequest), self::SETTINGS_SET_DISPLAY_NAME => SettingsSetDisplayName::execute($request, $rpcRequest), self::SETTINGS_DELETE_DISPLAY_NAME => SettingsDeleteDisplayName::execute($request, $rpcRequest), + self::SETTINGS_SET_DISPLAY_PICTURE => SettingsSetDisplayPicture::execute($request, $rpcRequest), + self::SETTINGS_DELETE_DISPLAY_PICTURE => SettingsDeleteDisplayPicture::execute($request, $rpcRequest), self::SETTINGS_ADD_SIGNING_KEY => SettingsAddSigningKey::execute($request, $rpcRequest), self::SETTINGS_GET_SIGNING_KEYS => SettingsGetSigningKeys::execute($request, $rpcRequest), @@ -159,7 +164,9 @@ self::SETTINGS_ADD_SIGNING_KEY, self::SETTINGS_GET_SIGNING_KEYS, self::SETTINGS_SET_DISPLAY_NAME, + self::SETTINGS_SET_DISPLAY_PICTURE, self::SETTINGS_SET_PASSWORD, + self::SETTINGS_UPDATE_PASSWORD, ]); // Prevent the user from deleting their display name if it is required @@ -168,10 +175,14 @@ $methods[] = self::SETTINGS_DELETE_DISPLAY_NAME; } - // Always allow the authenticated user to change their password - if(!in_array(SessionFlags::SET_PASSWORD, $session->getFlags())) + if(!Configuration::getRegistrationConfiguration()->isPasswordRequired()) { - $methods[] = self::SETTINGS_SET_PASSWORD; + $methods[] = self::SETTINGS_DELETE_PASSWORD; + } + + if(!Configuration::getRegistrationConfiguration()->isDisplayPictureRequired()) + { + $methods[] = self::SETTINGS_DELETE_DISPLAY_PICTURE; } } // If the session isn't authenticated nor a host, a limited set of methods is available @@ -213,6 +224,12 @@ { $methods[] = self::SETTINGS_SET_DISPLAY_NAME; } + + // If the flag `SET_DISPLAY_PICTURE` is set, then the user has to set a display picture + if($session->flagExists(SessionFlags::SET_DISPLAY_PICTURE)) + { + $methods[] = self::SETTINGS_DELETE_DISPLAY_PICTURE; + } } return $methods; diff --git a/src/Socialbox/Managers/RegisteredPeerManager.php b/src/Socialbox/Managers/RegisteredPeerManager.php index 0924d45..34fc37f 100644 --- a/src/Socialbox/Managers/RegisteredPeerManager.php +++ b/src/Socialbox/Managers/RegisteredPeerManager.php @@ -432,6 +432,7 @@ $peer = self::getPeer($peer); } + // TODO: Handle for external peers, needs a way to resolve peers to their external counterparts if($peer->isExternal()) { throw new InvalidArgumentException('Cannot update the display picture of an external peer');