2024-09-13 13:50:50 -04:00
|
|
|
<?php
|
|
|
|
|
2024-12-12 14:55:44 -05:00
|
|
|
namespace Socialbox\Enums;
|
2024-09-13 13:50:50 -04:00
|
|
|
|
2025-01-05 01:23:43 -05:00
|
|
|
use Socialbox\Classes\Configuration;
|
2024-12-23 19:02:37 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\AcceptCommunityGuidelines;
|
2024-12-14 00:43:19 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\AcceptPrivacyPolicy;
|
|
|
|
use Socialbox\Classes\StandardMethods\AcceptTermsOfService;
|
2025-01-10 18:09:47 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\Authenticate;
|
2025-01-07 15:25:32 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\GetAllowedMethods;
|
2024-12-23 19:02:37 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\GetCommunityGuidelines;
|
2024-12-14 00:43:19 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\GetPrivacyPolicy;
|
2024-12-12 14:55:44 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\GetSessionState;
|
2024-12-14 00:43:19 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\GetTermsOfService;
|
2024-12-12 14:55:44 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\Ping;
|
2025-01-10 15:16:02 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\ResolvePeer;
|
2025-01-03 18:30:50 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\SettingsAddSigningKey;
|
2025-01-07 15:25:32 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\SettingsDeleteBirthday;
|
2025-01-04 15:32:42 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\SettingsDeleteDisplayName;
|
2025-01-05 01:36:57 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\SettingsDeleteDisplayPicture;
|
2025-01-07 15:25:32 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\SettingsDeleteEmailAddress;
|
2025-01-05 01:23:43 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\SettingsDeletePassword;
|
2025-01-07 15:25:32 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\SettingsDeletePhoneNumber;
|
2025-01-03 18:30:50 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\SettingsGetSigningKeys;
|
2025-01-07 15:25:32 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\SettingsSetBirthday;
|
2024-12-24 15:05:35 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\SettingsSetDisplayName;
|
2025-01-05 01:36:57 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\SettingsSetDisplayPicture;
|
2025-01-07 15:25:32 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\SettingsSetEmailAddress;
|
2024-12-14 00:43:19 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\SettingsSetPassword;
|
2025-01-07 15:25:32 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\SettingsSetPhoneNumber;
|
2025-01-05 01:23:43 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\SettingsUpdatePassword;
|
2024-12-14 00:43:19 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\VerificationAnswerImageCaptcha;
|
|
|
|
use Socialbox\Classes\StandardMethods\VerificationGetImageCaptcha;
|
2025-01-07 15:25:32 -05:00
|
|
|
use Socialbox\Classes\StandardMethods\VerificationOtpAuthentication;
|
|
|
|
use Socialbox\Classes\StandardMethods\VerificationPasswordAuthentication;
|
2024-12-14 00:43:19 -05:00
|
|
|
use Socialbox\Enums\Flags\SessionFlags;
|
2025-01-07 15:25:32 -05:00
|
|
|
use Socialbox\Exceptions\DatabaseOperationException;
|
2024-12-12 14:55:44 -05:00
|
|
|
use Socialbox\Exceptions\StandardException;
|
|
|
|
use Socialbox\Interfaces\SerializableInterface;
|
2025-01-07 15:25:32 -05:00
|
|
|
use Socialbox\Managers\OneTimePasswordManager;
|
|
|
|
use Socialbox\Managers\PasswordManager;
|
2024-12-12 14:55:44 -05:00
|
|
|
use Socialbox\Objects\ClientRequest;
|
2025-01-07 15:25:32 -05:00
|
|
|
use Socialbox\Objects\Database\SessionRecord;
|
2024-12-12 14:55:44 -05:00
|
|
|
use Socialbox\Objects\RpcRequest;
|
2024-09-13 13:50:50 -04:00
|
|
|
|
2024-12-12 14:55:44 -05:00
|
|
|
enum StandardMethods : string
|
2024-09-13 13:50:50 -04:00
|
|
|
{
|
2024-12-12 14:55:44 -05:00
|
|
|
case PING = 'ping';
|
|
|
|
case GET_SESSION_STATE = 'getSessionState';
|
2025-01-07 15:25:32 -05:00
|
|
|
case GET_ALLOWED_METHODS = 'getAllowedMethods';
|
2024-12-14 00:43:19 -05:00
|
|
|
|
|
|
|
case GET_PRIVACY_POLICY = 'getPrivacyPolicy';
|
|
|
|
case ACCEPT_PRIVACY_POLICY = 'acceptPrivacyPolicy';
|
|
|
|
case GET_TERMS_OF_SERVICE = 'getTermsOfService';
|
|
|
|
case ACCEPT_TERMS_OF_SERVICE = 'acceptTermsOfService';
|
2024-12-20 15:02:57 -05:00
|
|
|
case GET_COMMUNITY_GUIDELINES = 'getCommunityGuidelines';
|
|
|
|
case ACCEPT_COMMUNITY_GUIDELINES = 'acceptCommunityGuidelines';
|
|
|
|
|
2025-01-07 15:26:32 -05:00
|
|
|
case VERIFICATION_EMAIL = 'verificationEmail'; // NOT IMPLEMENTED
|
|
|
|
case VERIFICATION_ANSWER_EMAIL = 'verificationAnswerEmail'; // NOT IMPLEMENTED
|
2024-12-20 15:02:57 -05:00
|
|
|
|
2025-01-07 15:26:32 -05:00
|
|
|
case VERIFICATION_SMS = 'verificationSms'; // NOT IMPLEMENTED
|
|
|
|
case VERIFICATION_ANSWER_SMS = 'verificationAnswerSms'; // NOT IMPLEMENTED
|
2024-12-20 15:02:57 -05:00
|
|
|
|
2025-01-07 15:26:32 -05:00
|
|
|
case VERIFICATION_PHONE_CALL = 'verificationPhoneCall'; // NOT IMPLEMENTED
|
|
|
|
case VERIFICATION_ANSWER_PHONE_CALL = 'verificationAnswerPhoneCall'; // NOT IMPLEMENTED
|
2024-12-14 00:43:19 -05:00
|
|
|
|
|
|
|
case VERIFICATION_GET_IMAGE_CAPTCHA = 'verificationGetImageCaptcha';
|
|
|
|
case VERIFICATION_ANSWER_IMAGE_CAPTCHA = 'verificationAnswerImageCaptcha';
|
|
|
|
|
2025-01-07 15:26:32 -05:00
|
|
|
case VERIFICATION_GET_TEXT_CAPTCHA = 'verificationGetTextCaptcha'; // NOT IMPLEMENTED
|
|
|
|
case VERIFICATION_ANSWER_TEXT_CAPTCHA = 'verificationAnswerTextCaptcha'; // NOT IMPLEMENTED
|
2024-12-20 15:02:57 -05:00
|
|
|
|
2025-01-07 15:26:32 -05:00
|
|
|
case VERIFICATION_GET_EXTERNAL_URL = 'verificationGetExternalUrl'; // NOT IMPLEMENTED
|
|
|
|
case VERIFICATION_ANSWER_EXTERNAL_URL = 'verificationAnswerExternalUrl'; // NOT IMPLEMENTED
|
2025-01-07 15:25:32 -05:00
|
|
|
|
|
|
|
case VERIFICATION_PASSWORD_AUTHENTICATION = 'verificationPasswordAuthentication';
|
|
|
|
case VERIFICATION_OTP_AUTHENTICATION = 'verificationOtpAuthentication';
|
2024-12-20 15:02:57 -05:00
|
|
|
|
2024-12-14 00:43:19 -05:00
|
|
|
case SETTINGS_SET_PASSWORD = 'settingsSetPassword';
|
2025-01-05 01:23:43 -05:00
|
|
|
case SETTINGS_UPDATE_PASSWORD = 'settingsUpdatePassword';
|
|
|
|
case SETTINGS_DELETE_PASSWORD = 'settingsDeletePassword';
|
2024-12-20 15:02:57 -05:00
|
|
|
case SETTINGS_SET_OTP = 'settingsSetOtp';
|
2025-01-07 15:25:32 -05:00
|
|
|
case SETTINGS_DELETE_OTP = 'settingsDeleteOtp';
|
2024-12-20 15:02:57 -05:00
|
|
|
case SETTINGS_SET_DISPLAY_NAME = 'settingsSetDisplayName';
|
2025-01-04 15:32:42 -05:00
|
|
|
case SETTINGS_DELETE_DISPLAY_NAME = 'settingsDeleteDisplayName';
|
2024-12-20 15:02:57 -05:00
|
|
|
case SETTINGS_SET_DISPLAY_PICTURE = 'settingsSetDisplayPicture';
|
2025-01-05 01:36:57 -05:00
|
|
|
case SETTINGS_DELETE_DISPLAY_PICTURE = 'settingsDeleteDisplayPicture';
|
2024-12-20 15:02:57 -05:00
|
|
|
case SETTINGS_SET_EMAIL = 'settingsSetEmail';
|
2025-01-07 15:25:32 -05:00
|
|
|
case SETTINGS_DELETE_EMAIL = 'settingsDeleteEmail';
|
2024-12-20 15:02:57 -05:00
|
|
|
case SETTINGS_SET_PHONE = 'settingsSetPhone';
|
2025-01-07 15:25:32 -05:00
|
|
|
case SETTINGS_DELETE_PHONE = 'settingsDeletePhone';
|
2024-12-20 15:02:57 -05:00
|
|
|
case SETTINGS_SET_BIRTHDAY = 'settingsSetBirthday';
|
2025-01-07 15:25:32 -05:00
|
|
|
case SETTINGS_DELETE_BIRTHDAY = 'settingsDeleteBirthday';
|
2024-12-12 14:55:44 -05:00
|
|
|
|
2025-01-03 18:30:50 -05:00
|
|
|
case SETTINGS_ADD_SIGNING_KEY = 'settingsAddSigningKey';
|
|
|
|
case SETTINGS_GET_SIGNING_KEYS = 'settingsGetSigningKeys';
|
|
|
|
|
2025-01-10 18:09:47 -05:00
|
|
|
case AUTHENTICATE = 'authenticate';
|
2025-01-10 15:16:02 -05:00
|
|
|
case RESOLVE_PEER = 'resolvePeer';
|
|
|
|
|
2024-12-12 14:55:44 -05:00
|
|
|
/**
|
2024-12-14 00:43:19 -05:00
|
|
|
* Executes the appropriate operation based on the current context and requests provided.
|
|
|
|
*
|
|
|
|
* @param ClientRequest $request The client request object containing necessary data for execution.
|
|
|
|
* @param RpcRequest $rpcRequest The RPC request object providing additional parameters for execution.
|
|
|
|
* @return SerializableInterface|null The result of the operation as a serializable interface or null if no operation matches.
|
|
|
|
* @throws StandardException If an error occurs during execution
|
2024-12-12 14:55:44 -05:00
|
|
|
*/
|
|
|
|
public function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
2024-09-13 13:50:50 -04:00
|
|
|
{
|
2024-12-12 14:55:44 -05:00
|
|
|
return match ($this)
|
|
|
|
{
|
|
|
|
self::PING => Ping::execute($request, $rpcRequest),
|
|
|
|
self::GET_SESSION_STATE => GetSessionState::execute($request, $rpcRequest),
|
2025-01-07 15:25:32 -05:00
|
|
|
self::GET_ALLOWED_METHODS => GetAllowedMethods::execute($request, $rpcRequest),
|
2024-12-14 00:43:19 -05:00
|
|
|
|
|
|
|
self::GET_PRIVACY_POLICY => GetPrivacyPolicy::execute($request, $rpcRequest),
|
|
|
|
self::ACCEPT_PRIVACY_POLICY => AcceptPrivacyPolicy::execute($request, $rpcRequest),
|
|
|
|
self::GET_TERMS_OF_SERVICE => GetTermsOfService::execute($request, $rpcRequest),
|
|
|
|
self::ACCEPT_TERMS_OF_SERVICE => AcceptTermsOfService::execute($request, $rpcRequest),
|
2024-12-23 19:02:37 -05:00
|
|
|
self::GET_COMMUNITY_GUIDELINES => GetCommunityGuidelines::execute($request, $rpcRequest),
|
|
|
|
self::ACCEPT_COMMUNITY_GUIDELINES => AcceptCommunityGuidelines::execute($request, $rpcRequest),
|
2024-12-14 00:43:19 -05:00
|
|
|
|
|
|
|
self::VERIFICATION_GET_IMAGE_CAPTCHA => VerificationGetImageCaptcha::execute($request, $rpcRequest),
|
|
|
|
self::VERIFICATION_ANSWER_IMAGE_CAPTCHA => VerificationAnswerImageCaptcha::execute($request, $rpcRequest),
|
2025-01-07 15:25:32 -05:00
|
|
|
|
|
|
|
self::VERIFICATION_PASSWORD_AUTHENTICATION => VerificationPasswordAuthentication::execute($request, $rpcRequest),
|
|
|
|
self::VERIFICATION_OTP_AUTHENTICATION => VerificationOtpAuthentication::execute($request, $rpcRequest),
|
2024-12-14 00:43:19 -05:00
|
|
|
|
|
|
|
self::SETTINGS_SET_PASSWORD => SettingsSetPassword::execute($request, $rpcRequest),
|
2025-01-05 01:23:43 -05:00
|
|
|
self::SETTINGS_UPDATE_PASSWORD => SettingsUpdatePassword::execute($request, $rpcRequest),
|
|
|
|
self::SETTINGS_DELETE_PASSWORD => SettingsDeletePassword::execute($request, $rpcRequest),
|
2024-12-24 15:05:35 -05:00
|
|
|
self::SETTINGS_SET_DISPLAY_NAME => SettingsSetDisplayName::execute($request, $rpcRequest),
|
2025-01-04 15:32:42 -05:00
|
|
|
self::SETTINGS_DELETE_DISPLAY_NAME => SettingsDeleteDisplayName::execute($request, $rpcRequest),
|
2025-01-05 01:36:57 -05:00
|
|
|
self::SETTINGS_SET_DISPLAY_PICTURE => SettingsSetDisplayPicture::execute($request, $rpcRequest),
|
|
|
|
self::SETTINGS_DELETE_DISPLAY_PICTURE => SettingsDeleteDisplayPicture::execute($request, $rpcRequest),
|
2025-01-07 15:25:32 -05:00
|
|
|
self::SETTINGS_SET_EMAIL => SettingsSetEmailAddress::execute($request, $rpcRequest),
|
|
|
|
self::SETTINGS_DELETE_EMAIL => SettingsDeleteEmailAddress::execute($request, $rpcRequest),
|
|
|
|
self::SETTINGS_SET_PHONE => SettingsSetPhoneNumber::execute($request, $rpcRequest),
|
|
|
|
self::SETTINGS_DELETE_PHONE => SettingsDeletePhoneNumber::execute($request, $rpcRequest),
|
|
|
|
self::SETTINGS_SET_BIRTHDAY => SettingsSetBirthday::execute($request, $rpcRequest),
|
|
|
|
self::SETTINGS_DELETE_BIRTHDAY => SettingsDeleteBirthday::execute($request, $rpcRequest),
|
2024-12-23 19:02:37 -05:00
|
|
|
|
2025-01-03 18:30:50 -05:00
|
|
|
self::SETTINGS_ADD_SIGNING_KEY => SettingsAddSigningKey::execute($request, $rpcRequest),
|
|
|
|
self::SETTINGS_GET_SIGNING_KEYS => SettingsGetSigningKeys::execute($request, $rpcRequest),
|
|
|
|
|
2025-01-10 18:09:47 -05:00
|
|
|
self::AUTHENTICATE => Authenticate::execute($request, $rpcRequest),
|
2025-01-10 15:16:02 -05:00
|
|
|
self::RESOLVE_PEER => ResolvePeer::execute($request, $rpcRequest),
|
|
|
|
|
2024-12-23 19:02:37 -05:00
|
|
|
default => $rpcRequest->produceError(StandardError::METHOD_NOT_ALLOWED, sprintf("The method %s is not supported by the server", $rpcRequest->getMethod()))
|
2024-12-12 14:55:44 -05:00
|
|
|
};
|
|
|
|
}
|
2024-12-14 00:43:19 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the access method is allowed for the given client request.
|
|
|
|
*
|
|
|
|
* @param ClientRequest $clientRequest The client request instance to check access against.
|
|
|
|
* @return void
|
2025-01-07 15:25:32 -05:00
|
|
|
* @throws DatabaseOperationException If an error occurs while checking the database for session information.
|
2024-12-14 00:43:19 -05:00
|
|
|
* @throws StandardException If the method is not allowed for the given client request.
|
|
|
|
*/
|
|
|
|
public function checkAccess(ClientRequest $clientRequest): void
|
|
|
|
{
|
|
|
|
if(in_array($this, self::getAllowedMethods($clientRequest)))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new StandardException(StandardError::METHOD_NOT_ALLOWED->getMessage(), StandardError::METHOD_NOT_ALLOWED);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines the list of allowed methods for a given client request.
|
|
|
|
*
|
|
|
|
* @param ClientRequest $clientRequest The client request for which allowed methods are determined.
|
|
|
|
* @return array Returns an array of allowed methods for the provided client request.
|
2025-01-07 15:25:32 -05:00
|
|
|
* @throws DatabaseOperationException If an error occurs while checking the database for session information.
|
2024-12-14 00:43:19 -05:00
|
|
|
*/
|
|
|
|
public static function getAllowedMethods(ClientRequest $clientRequest): array
|
|
|
|
{
|
2024-12-23 19:02:37 -05:00
|
|
|
// These methods should always accessible
|
2024-12-14 00:43:19 -05:00
|
|
|
$methods = [
|
2024-12-23 19:02:37 -05:00
|
|
|
// Important methods
|
|
|
|
self::PING, // Always allow the ping method
|
|
|
|
self::GET_SESSION_STATE, // The session state should always be accessible
|
2025-01-07 15:25:32 -05:00
|
|
|
self::GET_ALLOWED_METHODS, // Client should always be able to get the allowed methods
|
2024-12-23 19:02:37 -05:00
|
|
|
self::GET_PRIVACY_POLICY, // The user should always be able to get the privacy policy
|
|
|
|
self::GET_TERMS_OF_SERVICE, // The user should always be able to get the terms of service
|
|
|
|
self::GET_COMMUNITY_GUIDELINES, // The user should always be able to get the community guidelines
|
2024-12-14 00:43:19 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
$session = $clientRequest->getSession();
|
|
|
|
|
2025-01-07 15:25:32 -05:00
|
|
|
if($session === null)
|
|
|
|
{
|
|
|
|
return $methods;
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$external = $session->isExternal();
|
|
|
|
}
|
|
|
|
catch(DatabaseOperationException)
|
|
|
|
{
|
|
|
|
$external = false;
|
|
|
|
}
|
|
|
|
|
2025-01-05 01:23:43 -05:00
|
|
|
// If the session is external (eg; coming from a different server)
|
|
|
|
// Servers will have their own access control mechanisms
|
2025-01-07 15:25:32 -05:00
|
|
|
if($external)
|
2024-12-14 00:43:19 -05:00
|
|
|
{
|
2025-01-07 15:25:32 -05:00
|
|
|
$methods = array_merge($methods, self::getExternalMethods($clientRequest));
|
2024-12-14 00:43:19 -05:00
|
|
|
}
|
2025-01-05 01:23:43 -05:00
|
|
|
// If the session is authenticated, then allow additional method calls
|
|
|
|
elseif($session->isAuthenticated())
|
2024-12-14 00:43:19 -05:00
|
|
|
{
|
2025-01-07 15:25:32 -05:00
|
|
|
$methods = array_merge($methods, self::getAuthenticatedMethods());
|
|
|
|
}
|
|
|
|
// If the session isn't authenticated, check if it's a registering user
|
|
|
|
elseif($session->flagExists(SessionFlags::REGISTRATION_REQUIRED))
|
|
|
|
{
|
|
|
|
$methods = array_merge($methods, self::getRegistrationMethods($session));
|
|
|
|
}
|
|
|
|
// If the user is a registering peer, check if it's an authenticating one
|
|
|
|
elseif($session->flagExists(SessionFlags::AUTHENTICATION_REQUIRED))
|
|
|
|
{
|
|
|
|
$methods = array_merge($methods, self::getAuthenticationMethods($clientRequest));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $methods;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2025-01-10 18:09:47 -05:00
|
|
|
* Retrieves a list of external methods based on the client's session state.
|
|
|
|
*
|
|
|
|
* @param ClientRequest
|
|
|
|
*/
|
2025-01-07 15:25:32 -05:00
|
|
|
private static function getExternalMethods(ClientRequest $clientRequest): array
|
|
|
|
{
|
2025-01-10 18:09:47 -05:00
|
|
|
$methods = [];
|
|
|
|
|
|
|
|
$session = $clientRequest->getSession();
|
|
|
|
if(!$session->isAuthenticated() || $session->flagExists(SessionFlags::AUTHENTICATION_REQUIRED))
|
|
|
|
{
|
|
|
|
$methods[] = self::AUTHENTICATE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$methods[] = self::RESOLVE_PEER;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $methods;
|
2025-01-07 15:25:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves a list of authenticated user methods based on configuration settings.
|
|
|
|
*
|
|
|
|
* @return array An array of methods that are available to
|
|
|
|
*/
|
|
|
|
private static function getAuthenticatedMethods(): array
|
|
|
|
{
|
|
|
|
|
|
|
|
// These methods are always allowed for authenticated users
|
|
|
|
$methods = [
|
|
|
|
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,
|
|
|
|
self::SETTINGS_SET_OTP,
|
|
|
|
self::SETTINGS_SET_EMAIL,
|
|
|
|
self::SETTINGS_SET_PHONE,
|
2025-01-10 15:16:02 -05:00
|
|
|
self::SETTINGS_SET_BIRTHDAY,
|
|
|
|
self::RESOLVE_PEER
|
2025-01-07 15:25:32 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
// Prevent the user from deleting their display name if it is required
|
|
|
|
if(!Configuration::getRegistrationConfiguration()->isDisplayNameRequired())
|
|
|
|
{
|
|
|
|
$methods[] = self::SETTINGS_DELETE_DISPLAY_NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prevent the user from deleting their password if it is required
|
|
|
|
if(!Configuration::getRegistrationConfiguration()->isPasswordRequired())
|
|
|
|
{
|
|
|
|
$methods[] = self::SETTINGS_DELETE_PASSWORD;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prevent the user from deleting their display picture if it is required
|
|
|
|
if(!Configuration::getRegistrationConfiguration()->isDisplayPictureRequired())
|
|
|
|
{
|
|
|
|
$methods[] = self::SETTINGS_DELETE_DISPLAY_PICTURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prevent the user from deleting their OTP if it is required
|
|
|
|
if(!Configuration::getRegistrationConfiguration()->isOtpRequired())
|
|
|
|
{
|
|
|
|
$methods[] = self::SETTINGS_DELETE_OTP;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prevent the user from deleting their Phone Number if it is required
|
|
|
|
if(!Configuration::getRegistrationConfiguration()->isPhoneNumberRequired())
|
|
|
|
{
|
|
|
|
$methods[] = self::SETTINGS_DELETE_PHONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prevent the user from deleting their email address if it is required
|
|
|
|
if(!Configuration::getRegistrationConfiguration()->isEmailAddressRequired())
|
|
|
|
{
|
|
|
|
$methods[] = self::SETTINGS_DELETE_EMAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prevent the user from deleting their birthday if it is required
|
|
|
|
if(!Configuration::getRegistrationConfiguration()->isBirthdayRequired())
|
|
|
|
{
|
|
|
|
$methods[] = self::SETTINGS_DELETE_BIRTHDAY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $methods;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves a list of registration methods based on the session flags.
|
|
|
|
*
|
|
|
|
* @param SessionRecord $session The session record containing flags that determine available registration methods.
|
|
|
|
* @return array An array of registration methods available for the session.
|
|
|
|
*/
|
|
|
|
private static function getRegistrationMethods(SessionRecord $session): array
|
|
|
|
{
|
|
|
|
// Don't allow registration methods if registration is disabled
|
|
|
|
if(!Configuration::getRegistrationConfiguration()->isRegistrationEnabled())
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the flag `VER_PRIVACY_POLICY` is set, then the user can accept the privacy policy
|
|
|
|
if($session->flagExists(SessionFlags::VER_PRIVACY_POLICY))
|
|
|
|
{
|
|
|
|
$methods[] = self::ACCEPT_PRIVACY_POLICY;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the flag `VER_TERMS_OF_SERVICE` is set, then the user can accept the terms of service
|
|
|
|
if($session->flagExists(SessionFlags::VER_TERMS_OF_SERVICE))
|
|
|
|
{
|
|
|
|
$methods[] = self::ACCEPT_TERMS_OF_SERVICE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the flag `VER_COMMUNITY_GUIDELINES` is set, then the user can accept the community guidelines
|
|
|
|
if($session->flagExists(SessionFlags::VER_COMMUNITY_GUIDELINES))
|
|
|
|
{
|
|
|
|
$methods[] = self::ACCEPT_COMMUNITY_GUIDELINES;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the flag `VER_IMAGE_CAPTCHA` is set, then the user has to get and answer an image captcha
|
|
|
|
if($session->flagExists(SessionFlags::VER_IMAGE_CAPTCHA))
|
|
|
|
{
|
|
|
|
$methods[] = self::VERIFICATION_GET_IMAGE_CAPTCHA;
|
|
|
|
$methods[] = self::VERIFICATION_ANSWER_IMAGE_CAPTCHA;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the flag `SET_PASSWORD` is set, then the user has to set a password
|
|
|
|
if($session->flagExists(SessionFlags::SET_PASSWORD))
|
|
|
|
{
|
|
|
|
$methods[] = self::SETTINGS_SET_PASSWORD;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the flag `SET_OTP` is set, then the user has to set an OTP
|
|
|
|
if($session->flagExists(SessionFLags::SET_OTP))
|
|
|
|
{
|
|
|
|
$methods[] = self::SETTINGS_SET_OTP;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the flag `SET_DISPLAY_NAME` is set, then the user has to set a display name
|
|
|
|
if($session->flagExists(SessionFlags::SET_DISPLAY_NAME))
|
|
|
|
{
|
|
|
|
$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_SET_DISPLAY_PICTURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the flag `SET_EMAIL` is set, then the user has to set an email address
|
|
|
|
if($session->flagExists(SessionFlags::SET_EMAIL))
|
|
|
|
{
|
|
|
|
$methods[] = self::SETTINGS_SET_EMAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the flag `SET_PHONE` is set, then the user has to set a phone number
|
|
|
|
if($session->flagExists(SessionFlags::SET_PHONE))
|
|
|
|
{
|
|
|
|
$methods[] = self::SETTINGS_SET_PHONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the flag `SET_BIRTHDAY` is set, then the user has to set a birthday
|
|
|
|
if($session->flagExists(SessionFlags::SET_BIRTHDAY))
|
|
|
|
{
|
|
|
|
$methods[] = self::SETTINGS_SET_BIRTHDAY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $methods;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the list of authentication methods available for the given client request.
|
|
|
|
*
|
|
|
|
* @param ClientRequest $clientRequest The client request for which the authentication methods are determined.
|
|
|
|
* @return array The list of available authentication methods as an array of constants.
|
|
|
|
* @throws DatabaseOperationException If an error occurs while checking the database for authentication methods.
|
|
|
|
*/
|
|
|
|
private static function getAuthenticationMethods(ClientRequest $clientRequest): array
|
|
|
|
{
|
|
|
|
if(!Configuration::getAuthenticationConfiguration()->isEnabled())
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$methods = [];
|
|
|
|
|
|
|
|
if(Configuration::getAuthenticationConfiguration()->isImageCaptchaVerificationRequired())
|
|
|
|
{
|
|
|
|
$methods[] = self::VERIFICATION_GET_IMAGE_CAPTCHA;
|
|
|
|
$methods[] = self::VERIFICATION_ANSWER_IMAGE_CAPTCHA;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$peer = $clientRequest->getPeer();
|
|
|
|
|
|
|
|
if(PasswordManager::usesPassword($peer))
|
|
|
|
{
|
|
|
|
$methods[] = self::VERIFICATION_PASSWORD_AUTHENTICATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(OneTimePasswordManager::usesOtp($peer->getUuid()))
|
|
|
|
{
|
|
|
|
$methods[] = self::VERIFICATION_OTP_AUTHENTICATION;
|
2024-12-23 19:02:37 -05:00
|
|
|
}
|
|
|
|
|
2024-12-14 00:43:19 -05:00
|
|
|
return $methods;
|
|
|
|
}
|
2024-12-12 14:55:44 -05:00
|
|
|
}
|