Skip to content

Commit bbd2d35

Browse files
committed
[IMPROVES] Add backend mode override in Views
1 parent 511323a commit bbd2d35

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

‎App/Manager/Views/View.php‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@
1212
use CMW\Utils\Utils;
1313
use JetBrains\PhpStorm\ArrayShape;
1414
use JetBrains\PhpStorm\ExpectedValues;
15+
use function extract;
16+
use function in_array;
1517
use function is_file;
18+
use function is_null;
19+
use function ob_get_clean;
20+
use function ob_start;
21+
use function print_r;
1622

1723
class View
1824
{
@@ -25,6 +31,7 @@ class View
2531
private bool $needAdminControl;
2632
private bool $isAdminFile;
2733
private string $themeName;
34+
private bool $overrideBackendMode;
2835

2936
/**
3037
* @param string|null $package
@@ -40,13 +47,14 @@ public function __construct(?string $package = null, ?string $viewFile = null, ?
4047
$this->needAdminControl = false;
4148
$this->isAdminFile = $isAdminFile;
4249
$this->themeName = ThemeManager::getInstance()->getCurrentTheme()->name();
50+
$this->overrideBackendMode = false;
4351
}
4452

4553
/**
4654
* @param string $package
4755
* @param string $viewFile
4856
* @return void
49-
* @throws \CMW\Manager\Router\RouterException
57+
* @throws RouterException
5058
*/
5159
public static function basicPublicView(string $package, string $viewFile): void
5260
{
@@ -57,7 +65,7 @@ public static function basicPublicView(string $package, string $viewFile): void
5765
/**
5866
* @param string $package
5967
* @param string $viewFile
60-
* @return \CMW\Manager\Views\View
68+
* @return View
6169
*/
6270
public static function createPublicView(string $package, string $viewFile): View
6371
{
@@ -67,7 +75,7 @@ public static function createPublicView(string $package, string $viewFile): View
6775
/**
6876
* @param string $package
6977
* @param string $viewFile
70-
* @return \CMW\Manager\Views\View
78+
* @return View
7179
*/
7280
public static function createAdminView(string $package, string $viewFile): View
7381
{
@@ -264,6 +272,17 @@ public function setCustomTemplate(string $path): self
264272
return $this;
265273
}
266274

275+
/**
276+
* @param bool $overrideBackendMode
277+
* @return View
278+
* If true, the view will be displayed even if the backend mode is enabled
279+
*/
280+
public function setOverrideBackendMode(bool $overrideBackendMode): self
281+
{
282+
$this->overrideBackendMode = $overrideBackendMode;
283+
return $this;
284+
}
285+
267286
/**
268287
* @return string
269288
*/
@@ -438,6 +457,10 @@ private function backendView(): void
438457
{
439458
$isBackendModeEnabled = EnvManager::getInstance()->getValue('ENABLE_BACKEND_MODE') === 'true';
440459

460+
if ($this->overrideBackendMode) {
461+
return;
462+
}
463+
441464
if ($isBackendModeEnabled && !$this->needAdminControl) {
442465
print_r(
443466
APIManager::createResponse(

‎App/Package/Users/Controllers/UsersLoginController.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use function is_null;
3535
use function mb_strtolower;
3636
use function strlen;
37+
use function strtotime;
3738
use function time;
3839

3940
/**
@@ -235,7 +236,9 @@ private function showLogin2Fa(): void
235236
ErrorManager::showCustomErrorPage("File not found", "The file $filePath doesn't exist.");
236237
}
237238

238-
View::createPublicView('Users', '2fa')->view();
239+
View::createPublicView('Users', '2fa')
240+
->setOverrideBackendMode(true)
241+
->view();
239242
}
240243

241244
private function enforceLogin2Fa(UserEntity $user): void

0 commit comments

Comments
 (0)