mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
cs
This commit is contained in:
@@ -51,7 +51,12 @@ class ActionRenderer
|
||||
*/
|
||||
public function write(Response $response, Params $params): void
|
||||
{
|
||||
$body = $this->render($params->getController(), $params->getAction(), $params->getData());
|
||||
$body = $this->render(
|
||||
$params->getController(),
|
||||
$params->getAction(),
|
||||
$params->getData(),
|
||||
$params->initAuth()
|
||||
);
|
||||
|
||||
$this->clientManager->writeHeaders($response);
|
||||
$response->writeBody($body);
|
||||
@@ -61,12 +66,15 @@ class ActionRenderer
|
||||
* @deprecated Use`write`.
|
||||
* @param ?array<string,mixed> $data
|
||||
*/
|
||||
public function render(string $controller, string $action, ?array $data = null): string
|
||||
public function render(string $controller, string $action, ?array $data = null, bool $initAuth = false): string
|
||||
{
|
||||
$encodedData = Json::encode($data);
|
||||
|
||||
$initAuthPart = $initAuth ? "app.initAuth();" : '';
|
||||
|
||||
$script =
|
||||
"
|
||||
{$initAuthPart}
|
||||
app.doAction({
|
||||
controllerClassName: '{$controller}',
|
||||
action: '{$action}',
|
||||
|
||||
@@ -38,6 +38,7 @@ class Params
|
||||
private string $action;
|
||||
/** @var ?array<string, mixed> */
|
||||
private ?array $data;
|
||||
private bool $initAuth = false;
|
||||
|
||||
/**
|
||||
* @param ?array<string, mixed> $data
|
||||
@@ -57,6 +58,25 @@ class Params
|
||||
return new self($controller, $action, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public function withData(array $data): self
|
||||
{
|
||||
$obj = clone $this;
|
||||
$obj->data = $data;
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function withInitAuth(bool $initAuth = true): self
|
||||
{
|
||||
$obj = clone $this;
|
||||
$obj->initAuth = $initAuth;
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function getController(): string
|
||||
{
|
||||
return $this->controller;
|
||||
@@ -74,4 +94,9 @@ class Params
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function initAuth(): bool
|
||||
{
|
||||
return $this->initAuth;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,14 +29,10 @@
|
||||
|
||||
namespace Espo\Core\Utils;
|
||||
|
||||
use Espo\Core\{
|
||||
Api\Response,
|
||||
Api\ResponseWrapper,
|
||||
Utils\File\Manager as FileManager,
|
||||
Utils\Client\DevModeJsFileListProvider,
|
||||
Utils\Module,
|
||||
Utils\Json,
|
||||
};
|
||||
use Espo\Core\Api\Response;
|
||||
use Espo\Core\Api\ResponseWrapper;
|
||||
use Espo\Core\Utils\Client\DevModeJsFileListProvider;
|
||||
use Espo\Core\Utils\File\Manager as FileManager;
|
||||
|
||||
use Slim\Psr7\Response as Psr7Response;
|
||||
use Slim\ResponseEmitter;
|
||||
@@ -47,29 +43,21 @@ use Slim\ResponseEmitter;
|
||||
class ClientManager
|
||||
{
|
||||
protected string $mainHtmlFilePath = 'html/main.html';
|
||||
|
||||
protected string $runScript = "app.start();";
|
||||
|
||||
private string $basePath = '';
|
||||
|
||||
private string $libsConfigPath = 'client/cfg/libs.json';
|
||||
|
||||
private Config $config;
|
||||
|
||||
private ThemeManager $themeManager;
|
||||
|
||||
private Metadata $metadata;
|
||||
|
||||
private FileManager $fileManager;
|
||||
|
||||
private DevModeJsFileListProvider $devModeJsFileListProvider;
|
||||
|
||||
private Module $module;
|
||||
|
||||
private string $nonce;
|
||||
|
||||
private const APP_DESCRIPTION = "EspoCRM - Open Source CRM application.";
|
||||
|
||||
private Config $config;
|
||||
private ThemeManager $themeManager;
|
||||
private Metadata $metadata;
|
||||
private FileManager $fileManager;
|
||||
private DevModeJsFileListProvider $devModeJsFileListProvider;
|
||||
private Module $module;
|
||||
|
||||
public function __construct(
|
||||
Config $config,
|
||||
ThemeManager $themeManager,
|
||||
|
||||
@@ -34,14 +34,13 @@ use Espo\Core\EntryPoint\EntryPoint;
|
||||
use Espo\Core\EntryPoint\Traits\NoAuth;
|
||||
use Espo\Core\Api\Request;
|
||||
use Espo\Core\Api\Response;
|
||||
use Espo\Core\Utils\ClientManager;
|
||||
use Espo\Core\Utils\Json;
|
||||
use Espo\Core\Utils\Client\ActionRenderer;
|
||||
|
||||
class LoginAs implements EntryPoint
|
||||
{
|
||||
use NoAuth;
|
||||
|
||||
public function __construct(private ClientManager $clientManager) {}
|
||||
public function __construct(private ActionRenderer $actionRenderer) {}
|
||||
|
||||
/**
|
||||
* @throws BadRequest
|
||||
@@ -54,24 +53,14 @@ class LoginAs implements EntryPoint
|
||||
throw new BadRequest("No anotherUser.");
|
||||
}
|
||||
|
||||
$data = [
|
||||
'anotherUser' => $anotherUser,
|
||||
'username' => $request->getQueryParam('username'),
|
||||
];
|
||||
|
||||
$encodedData = Json::encode($data);
|
||||
|
||||
$script =
|
||||
"
|
||||
app.initAuth();
|
||||
app.doAction({
|
||||
controllerClassName: 'controllers/login-as',
|
||||
action: 'login',
|
||||
options: {$encodedData},
|
||||
});
|
||||
";
|
||||
|
||||
$this->clientManager->writeHeaders($response);
|
||||
$response->writeBody($this->clientManager->render($script));
|
||||
$this->actionRenderer->write(
|
||||
$response,
|
||||
ActionRenderer\Params::create('controllers/login-as', 'login')
|
||||
->withData([
|
||||
'anotherUser' => $anotherUser,
|
||||
'username' => $request->getQueryParam('username'),
|
||||
])
|
||||
->withInitAuth()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user