Skip to content

EspoCRM – Open Source CRM Application

Action rederer login

Yuriid6a503b44a51
diff --git a/application/Espo/Core/Utils/Client/ActionRenderer.php b/application/Espo/Core/Utils/Client/ActionRenderer.php
index 075e768f94..19d96104a8 100644
--- a/application/Espo/Core/Utils/Client/ActionRenderer.php
+++ b/application/Espo/Core/Utils/Client/ActionRenderer.php
@@ -58,6 +58,7 @@ class ActionRenderer
pageTitle: $params->getPageTitle(),
theme: $params->getTheme(),
direction: $params->getDirection(),
+ login: $params->login(),
);
$securityParams = new SecurityParams(
@@ -81,21 +82,34 @@ class ActionRenderer
?string $pageTitle,
?string $theme,
?Direction $direction,
+ bool $login,
): string {
$encodedData = Json::encode($data);
- $initAuthPart = $initAuth ? "app.initAuth();" : '';
+ $doActionPart = <<<EOF
+ app.doAction({
+ controllerClassName: '$controller',
+ action: '$action',
+ options: $encodedData,
+ });
+ EOF;
- $script =
- "
- {$initAuthPart}
- app.doAction({
- controllerClassName: '$controller',
- action: '$action',
- options: $encodedData,
- });
- ";
+ if ($login) {
+ $script = <<<EOF
+ app.start({
+ onAuth: () => {
+ $doActionPart
+ },
+ });
+ EOF;
+ } else {
+ $initAuthPart = $initAuth ? "app.initAuth();\n" : '';
+
+ $script = <<<EOF
+ {$initAuthPart}
+ EOF . "\n" . $doActionPart;
+ }
$params = new RenderParams(
runScript: $script,
@@ -103,6 +117,7 @@ class ActionRenderer
pageTitle: $pageTitle,
theme: $theme,
direction: $direction,
+ useRouter: false,
);
return $this->clientManager->render($params);
diff --git a/application/Espo/Core/Utils/Client/ActionRenderer/Params.php b/application/Espo/Core/Utils/Client/ActionRenderer/Params.php
index 971b48a48a..616a2666a3 100644
--- a/application/Espo/Core/Utils/Client/ActionRenderer/Params.php
+++ b/application/Espo/Core/Utils/Client/ActionRenderer/Params.php
@@ -47,6 +47,7 @@ class Params
private ?string $pageTitle = null;
private ?string $theme = null;
private ?Direction $direction = null;
+ private bool $login = false;
/**
* @param ?array<string, mixed> $data
@@ -140,6 +141,17 @@ class Params
return $obj;
}
+ /**
+ * @since 10.1.0
+ */
+ public function withLogin(bool $login = true): self
+ {
+ $obj = clone $this;
+ $obj->login = $login;
+
+ return $obj;
+ }
+
public function getController(): string
{
return $this->controller;
@@ -201,4 +213,12 @@ class Params
{
return $this->direction;
}
+
+ /**
+ * @since 10.1.0
+ */
+ public function login(): bool
+ {
+ return $this->login;
+ }
}
diff --git a/application/Espo/Core/Utils/Client/RenderParams.php b/application/Espo/Core/Utils/Client/RenderParams.php
index c21ad515be..6f46a6c570 100644
--- a/application/Espo/Core/Utils/Client/RenderParams.php
+++ b/application/Espo/Core/Utils/Client/RenderParams.php
@@ -39,6 +39,7 @@ readonly class RenderParams
* @param ?string $pageTitle A page title. Since 9.1.0.
* @param ?string $theme A page theme name.
* @param ?Direction $direction A document direction.
+ * @param bool $useRouter Use the frontend router. As of v10.1.0.
*/
public function __construct(
public ?string $runScript = null,
@@ -46,5 +47,6 @@ readonly class RenderParams
public ?string $pageTitle = null,
public ?string $theme = null,
public ?Direction $direction = null,
+ public bool $useRouter = true,
) {}
}
diff --git a/application/Espo/Core/Utils/ClientManager.php b/application/Espo/Core/Utils/ClientManager.php
index b245a0527d..34965c07a4 100644
--- a/application/Espo/Core/Utils/ClientManager.php
+++ b/application/Espo/Core/Utils/ClientManager.php
@@ -181,6 +181,7 @@ class ClientManager
pageTitle: $params->pageTitle,
theme: $params->theme,
direction: $params->direction,
+ useRouter: $params->useRouter,
);
}
@@ -196,6 +197,7 @@ class ClientManager
?string $pageTitle = null,
?string $theme = null,
?Direction $direction = null,
+ bool $useRouter = true,
): string {
$runScript ??= $this->runScript;
@@ -279,6 +281,7 @@ class ClientManager
'applicationDescription' =>
$this->escapeValue($this->config->get('applicationDescription') ?? self::APP_DESCRIPTION),
'nonce' => $this->nonce,
+ 'useRouter' => $useRouter ? 'true' : 'false',
'loaderParams' => Json::encode([
'basePath' => $this->basePath,
'cacheTimestamp' => $loaderCacheTimestamp,
diff --git a/client/src/app.js b/client/src/app.js
index 8e831ddc87..28d5cf39a6 100644
--- a/client/src/app.js
+++ b/client/src/app.js
@@ -90,6 +90,7 @@ class App {
*/
this.useCache = options.useCache || this.useCache;
+ this.useRouter = options.useRouter ?? true;
this.apiUrl = options.apiUrl || this.apiUrl;
/**
@@ -146,6 +147,12 @@ class App {
*/
useCache = false
+ /**
+ * @private
+ * @type {boolean}
+ */
+ useRouter
+
/**
* @protected
* @type {User}
@@ -453,9 +460,11 @@ class App {
/**
* Start the application.
+ *
+ * @param {{onAuth: () => void}} [options]
*/
- start() {
- this.initAuth();
+ start(options = {}) {
+ this.initAuth(options.onAuth);
this.started = true;
@@ -465,7 +474,11 @@ class App {
return;
}
- this.initUserData(null, () => this.onAuth());
+ this.initUserData(null, async () => {
+ await this.onAuth(false);
+
+ options?.onAuth();
+ });
}
/**
@@ -557,7 +570,9 @@ class App {
this.acl.implementationClassMap = aclImplementationClassMap;
- this.initRouter();
+ if (this.useRouter) {
+ this.initRouter();
+ }
this.webSocketManager.subscribe('appParamsUpdate', () => this.appParams.load());
}
@@ -889,8 +904,9 @@ class App {
/**
* @public
+ * @param {() => void} [callback]
*/
- initAuth() {
+ initAuth(callback) {
this.auth = this.storage.get('user', 'auth') || null;
this.anotherUser = this.storage.get('user', 'anotherUser') || null;
@@ -915,7 +931,14 @@ class App {
this.storage.set('user', 'anotherUser', this.anotherUser);
this.setCookieAuth(userName, token);
- this.initUserData(data, () => this.onAuth(true));
+
+ this.initUserData(data, async () => {
+ await this.onAuth(true);
+
+ if (callback) {
+ callback();
+ }
+ });
});
this.baseController.on('logout', () => this.logout());
@@ -1599,6 +1622,7 @@ class App {
* @property {Number|null} [cacheTimestamp] A cache timestamp.
* @property {Number|null} [appTimestamp] An application timestamp.
* @property {string|null} [theme] A theme name.
+ * @property {boolean} [useRouter = true] Use router.
*/
Object.assign(App.prototype, Events);
diff --git a/html/main.html b/html/main.html
index 5d39f7e068..5b341485c3 100644
--- a/html/main.html
+++ b/html/main.html
@@ -32,6 +32,7 @@
internalModuleList: {{internalModuleList}},
bundledModuleList: {{bundledModuleList}},
theme: {{theme}},
+ useRouter: {{useRouter}},
}, app => {
loadedApp = app;