Restructured StandardMethod Namespaces

This commit is contained in:
netkas 2025-01-29 15:52:38 -05:00
parent d6e397247a
commit 1e10e761db
38 changed files with 72 additions and 82 deletions

View file

@ -0,0 +1,62 @@
<?php
namespace Socialbox\Classes\StandardMethods\Verification;
use Exception;
use Socialbox\Abstracts\Method;
use Socialbox\Classes\Cryptography;
use Socialbox\Enums\Flags\SessionFlags;
use Socialbox\Enums\StandardError;
use Socialbox\Exceptions\CryptographyException;
use Socialbox\Exceptions\StandardException;
use Socialbox\Interfaces\SerializableInterface;
use Socialbox\Managers\PasswordManager;
use Socialbox\Managers\SessionManager;
use Socialbox\Objects\ClientRequest;
use Socialbox\Objects\RpcRequest;
class VerificationPasswordAuthentication extends Method
{
/**
* @inheritDoc
*/
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
{
if(!$rpcRequest->containsParameter('password'))
{
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, "Missing 'password' parameter");
}
if(!Cryptography::validateSha512($rpcRequest->getParameter('password')))
{
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, "Invalid 'password' parameter, must be a valid SHA-512 hash");
}
$session = $request->getSession();
if(!$session->flagExists(SessionFlags::VER_PASSWORD))
{
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Password verification is not required at this time');
}
try
{
$result = PasswordManager::verifyPassword($request->getPeer()->getUuid(), $rpcRequest->getParameter('password'));
if($result)
{
SessionManager::updateFlow($request->getSession(), [SessionFlags::VER_PASSWORD]);
}
}
catch (CryptographyException)
{
return $rpcRequest->produceResponse(false);
}
catch (Exception $e)
{
throw new StandardException('Failed to verify password due to an internal exception', StandardError::INTERNAL_SERVER_ERROR, $e);
}
return $rpcRequest->produceResponse($result);
}
}