Refactor and extend configuration classes.
This commit is contained in:
parent
01253d5115
commit
395e6b95ff
24 changed files with 1158 additions and 682 deletions
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace Socialbox\Classes\StandardMethods;
|
||||
|
||||
use Socialbox\Abstracts\Method;
|
||||
use Socialbox\Enums\Flags\SessionFlags;
|
||||
use Socialbox\Enums\StandardError;
|
||||
use Socialbox\Exceptions\DatabaseOperationException;
|
||||
use Socialbox\Interfaces\SerializableInterface;
|
||||
use Socialbox\Managers\SessionManager;
|
||||
use Socialbox\Objects\ClientRequest;
|
||||
use Socialbox\Objects\RpcRequest;
|
||||
|
||||
class AcceptCommunityGuidelines extends Method
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||
{
|
||||
try
|
||||
{
|
||||
// Remove the verification flag
|
||||
SessionManager::removeFlags($request->getSessionUuid(), [SessionFlags::VER_COMMUNITY_GUIDELINES]);
|
||||
|
||||
// Check & update the session flow
|
||||
SessionManager::updateFlow($request->getSession());
|
||||
}
|
||||
catch (DatabaseOperationException $e)
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||
}
|
||||
|
||||
return $rpcRequest->produceResponse(true);
|
||||
}
|
||||
}
|
|
@ -21,28 +21,17 @@
|
|||
{
|
||||
try
|
||||
{
|
||||
// Remove the verification flag
|
||||
SessionManager::removeFlags($request->getSessionUuid(), [SessionFlags::VER_PRIVACY_POLICY]);
|
||||
|
||||
// Check & update the session flow
|
||||
SessionManager::updateFlow($request->getSession());
|
||||
}
|
||||
catch (DatabaseOperationException $e)
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||
}
|
||||
|
||||
// Check if all registration flags are removed
|
||||
if(SessionFlags::isComplete($request->getSession()->getFlags()))
|
||||
{
|
||||
// Set the session as authenticated
|
||||
try
|
||||
{
|
||||
SessionManager::setAuthenticated($request->getSessionUuid(), true);
|
||||
SessionManager::removeFlags($request->getSessionUuid(), [SessionFlags::REGISTRATION_REQUIRED, SessionFlags::AUTHENTICATION_REQUIRED]);
|
||||
}
|
||||
catch (DatabaseOperationException $e)
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||
}
|
||||
}
|
||||
|
||||
return $rpcRequest->produceResponse(true);
|
||||
}
|
||||
}
|
|
@ -20,28 +20,17 @@
|
|||
{
|
||||
try
|
||||
{
|
||||
// Remove the verification flag
|
||||
SessionManager::removeFlags($request->getSessionUuid(), [SessionFlags::VER_TERMS_OF_SERVICE]);
|
||||
|
||||
// Check & update the session flow
|
||||
SessionManager::updateFlow($request->getSession());
|
||||
}
|
||||
catch (DatabaseOperationException $e)
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||
}
|
||||
|
||||
// Check if all registration flags are removed
|
||||
if(SessionFlags::isComplete($request->getSession()->getFlags()))
|
||||
{
|
||||
// Set the session as authenticated
|
||||
try
|
||||
{
|
||||
SessionManager::setAuthenticated($request->getSessionUuid(), true);
|
||||
SessionManager::removeFlags($request->getSessionUuid(), [SessionFlags::REGISTRATION_REQUIRED, SessionFlags::AUTHENTICATION_REQUIRED]);
|
||||
}
|
||||
catch (DatabaseOperationException $e)
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||
}
|
||||
}
|
||||
|
||||
return $rpcRequest->produceResponse(true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Socialbox\Classes\StandardMethods;
|
||||
|
||||
use Socialbox\Abstracts\Method;
|
||||
use Socialbox\Classes\Configuration;
|
||||
use Socialbox\Classes\Resources;
|
||||
use Socialbox\Enums\StandardError;
|
||||
use Socialbox\Interfaces\SerializableInterface;
|
||||
use Socialbox\Objects\ClientRequest;
|
||||
use Socialbox\Objects\RpcRequest;
|
||||
use Socialbox\Objects\Standard\ServerDocument;
|
||||
|
||||
class GetCommunityGuidelines extends Method
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||
{
|
||||
return $rpcRequest->produceResponse(new ServerDocument([
|
||||
'last_updated' => Configuration::getRegistrationConfiguration()->getCommunityGuidelinesDate(),
|
||||
'title' => 'Community Guidelines',
|
||||
'content' => Resources::getCommunityGuidelines()
|
||||
]));
|
||||
}
|
||||
}
|
|
@ -3,11 +3,13 @@
|
|||
namespace Socialbox\Classes\StandardMethods;
|
||||
|
||||
use Socialbox\Abstracts\Method;
|
||||
use Socialbox\Classes\Configuration;
|
||||
use Socialbox\Classes\Resources;
|
||||
use Socialbox\Enums\StandardError;
|
||||
use Socialbox\Interfaces\SerializableInterface;
|
||||
use Socialbox\Objects\ClientRequest;
|
||||
use Socialbox\Objects\RpcRequest;
|
||||
use Socialbox\Objects\Standard\ServerDocument;
|
||||
|
||||
class GetPrivacyPolicy extends Method
|
||||
{
|
||||
|
@ -17,6 +19,10 @@
|
|||
*/
|
||||
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||
{
|
||||
return $rpcRequest->produceResponse(Resources::getPrivacyPolicy());
|
||||
return $rpcRequest->produceResponse(new ServerDocument([
|
||||
'last_updated' => Configuration::getRegistrationConfiguration()->getPrivacyPolicyDate(),
|
||||
'title' => 'Privacy Policy',
|
||||
'content' => Resources::getPrivacyPolicy()
|
||||
]));
|
||||
}
|
||||
}
|
|
@ -3,11 +3,13 @@
|
|||
namespace Socialbox\Classes\StandardMethods;
|
||||
|
||||
use Socialbox\Abstracts\Method;
|
||||
use Socialbox\Classes\Configuration;
|
||||
use Socialbox\Classes\Resources;
|
||||
use Socialbox\Enums\StandardError;
|
||||
use Socialbox\Interfaces\SerializableInterface;
|
||||
use Socialbox\Objects\ClientRequest;
|
||||
use Socialbox\Objects\RpcRequest;
|
||||
use Socialbox\Objects\Standard\ServerDocument;
|
||||
|
||||
class GetTermsOfService extends Method
|
||||
{
|
||||
|
@ -17,6 +19,10 @@
|
|||
*/
|
||||
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||
{
|
||||
return $rpcRequest->produceResponse(Resources::getTermsOfService());
|
||||
return $rpcRequest->produceResponse(new ServerDocument([
|
||||
'last_updated' => Configuration::getRegistrationConfiguration()->getTermsOfServiceDate(),
|
||||
'title' => 'Terms of Service',
|
||||
'content' => Resources::getTermsOfService()
|
||||
]));
|
||||
}
|
||||
}
|
|
@ -60,6 +60,7 @@
|
|||
|
||||
// Build the captcha
|
||||
// Returns HTML base64 encoded image of the captcha
|
||||
// Important note: Must always be HTML-BASE64 which means it must be prefixed with `data:image/jpeg;base64,`
|
||||
return $rpcRequest->produceResponse(new ImageCaptcha([
|
||||
'expires' => $captchaRecord->getExpires(),
|
||||
'content' => (new CaptchaBuilder($answer))->build()->inline()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue