From 367cb56a6f07d5616908edba4a2d49399a5f9e09 Mon Sep 17 00:00:00 2001 From: Michal Dziekonski Date: Thu, 4 Feb 2021 02:29:50 +0100 Subject: [PATCH] GH-150 Move login page's display logic to a separate module --- login.php | 26 ++----- modules/session/_includes.php | 14 ++++ modules/session/index.php | 5 ++ .../screens/LoginView/LoginView.component.php | 33 +++++++++ .../LoginForm/LoginForm.component.php | 68 +++++++++++++++++++ .../components/LoginForm/form_body.tpl | 40 +++++++++++ .../LoginView/components/LoginForm/index.php | 5 ++ .../screens/LoginView/components/index.php | 5 ++ modules/session/screens/LoginView/index.php | 5 ++ modules/session/screens/index.php | 5 ++ 10 files changed, 184 insertions(+), 22 deletions(-) create mode 100644 modules/session/_includes.php create mode 100644 modules/session/index.php create mode 100644 modules/session/screens/LoginView/LoginView.component.php create mode 100644 modules/session/screens/LoginView/components/LoginForm/LoginForm.component.php create mode 100644 modules/session/screens/LoginView/components/LoginForm/form_body.tpl create mode 100644 modules/session/screens/LoginView/components/LoginForm/index.php create mode 100644 modules/session/screens/LoginView/components/index.php create mode 100644 modules/session/screens/LoginView/index.php create mode 100644 modules/session/screens/index.php diff --git a/login.php b/login.php index ca22725c1..d140b537e 100644 --- a/login.php +++ b/login.php @@ -215,30 +215,12 @@ includeLang('login'); } -$_Lang['PHP_InsertUniCode'] = LOGINPAGE_UNIVERSUMCODE; -$_Lang['PHP_Insert_LangSelectors'] = []; +include($_EnginePath . 'modules/session/_includes.php'); -foreach (UNIENGINE_LANGS_AVAILABLE as $langKey) { - $langData = $_Lang['LanguagesAvailable'][$langKey]; +use UniEngine\Engine\Modules\Session; - $_Lang['PHP_Insert_LangSelectors'][] = ( - "" . - "{$langData['flag_emoji']}" . - "" - ); -} -$_Lang['PHP_Insert_LangSelectors'] = implode('  ', $_Lang['PHP_Insert_LangSelectors']); +$pageView = Session\Screens\LoginView\render([]); -if($_GameConfig['game_disable']) -{ - $_Lang['type'] = 'button" onclick="alert(\''.str_replace('
', "\n", $_GameConfig['close_reason']).'\')'; - $_Lang['LoginButton'] = $_Lang['Body_ServerOffline']; -} -else -{ - $_Lang['type'] = 'submit'; - $_Lang['LoginButton'] = $_Lang['Body_Submit']; -} -display(parsetemplate(gettemplate('login_body'), $_Lang), $_Lang['Page_Title']); +display($pageView['componentHTML'], $_Lang['Page_Title']); ?> diff --git a/modules/session/_includes.php b/modules/session/_includes.php new file mode 100644 index 000000000..aedeebb41 --- /dev/null +++ b/modules/session/_includes.php @@ -0,0 +1,14 @@ + diff --git a/modules/session/index.php b/modules/session/index.php new file mode 100644 index 000000000..bc99142d1 --- /dev/null +++ b/modules/session/index.php @@ -0,0 +1,5 @@ + diff --git a/modules/session/screens/LoginView/LoginView.component.php b/modules/session/screens/LoginView/LoginView.component.php new file mode 100644 index 000000000..a04f74743 --- /dev/null +++ b/modules/session/screens/LoginView/LoginView.component.php @@ -0,0 +1,33 @@ + $viewComponent['componentHTML'], + ]; +} + +?> diff --git a/modules/session/screens/LoginView/components/LoginForm/LoginForm.component.php b/modules/session/screens/LoginView/components/LoginForm/LoginForm.component.php new file mode 100644 index 000000000..9e155430f --- /dev/null +++ b/modules/session/screens/LoginView/components/LoginForm/LoginForm.component.php @@ -0,0 +1,68 @@ + $localTemplateLoader('form_body'), + ]; + + $renderLangSelectorOptions = function () use ($_Lang) { + $options = []; + + foreach (UNIENGINE_LANGS_AVAILABLE as $langKey) { + $langData = $_Lang['LanguagesAvailable'][$langKey]; + + $options[] = ( + "" . + "{$langData['flag_emoji']}" . + "" + ); + } + + return implode('  ', $options); + }; + + $isGameDisabled = $_GameConfig['game_disable']; + $gameDisabledReason = $_GameConfig['close_reason']; + + $additionalTplData = [ + 'PHP_InsertUniCode' => LOGINPAGE_UNIVERSUMCODE, + 'PHP_Insert_LangSelectors' => $renderLangSelectorOptions(), + + 'type' => ( + $isGameDisabled ? + 'button" onclick="alert(\'' . str_replace('
', "\n", $gameDisabledReason) . '\')' : + 'submit' + ), + 'LoginButton' => ( + $isGameDisabled ? + $_Lang['Body_ServerOffline'] : + $_Lang['Body_Submit'] + ), + ]; + + $componentHTML = parsetemplate( + $tplBodyCache['pageBody'], + array_merge( + $_Lang, + $additionalTplData + ) + ); + + return [ + 'componentHTML' => $componentHTML + ]; +} + +?> diff --git a/modules/session/screens/LoginView/components/LoginForm/form_body.tpl b/modules/session/screens/LoginView/components/LoginForm/form_body.tpl new file mode 100644 index 000000000..73b105e06 --- /dev/null +++ b/modules/session/screens/LoginView/components/LoginForm/form_body.tpl @@ -0,0 +1,40 @@ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{Page_Title}
 
{Body_LostPass}
{Body_LostCode}
+ {Body_Register} | {Body_Contact} +
 
+ {PHP_Insert_LangSelectors} +
 
+ Powered by UniEngine +
+
diff --git a/modules/session/screens/LoginView/components/LoginForm/index.php b/modules/session/screens/LoginView/components/LoginForm/index.php new file mode 100644 index 000000000..bc99142d1 --- /dev/null +++ b/modules/session/screens/LoginView/components/LoginForm/index.php @@ -0,0 +1,5 @@ + diff --git a/modules/session/screens/LoginView/components/index.php b/modules/session/screens/LoginView/components/index.php new file mode 100644 index 000000000..bc99142d1 --- /dev/null +++ b/modules/session/screens/LoginView/components/index.php @@ -0,0 +1,5 @@ + diff --git a/modules/session/screens/LoginView/index.php b/modules/session/screens/LoginView/index.php new file mode 100644 index 000000000..bc99142d1 --- /dev/null +++ b/modules/session/screens/LoginView/index.php @@ -0,0 +1,5 @@ + diff --git a/modules/session/screens/index.php b/modules/session/screens/index.php new file mode 100644 index 000000000..bc99142d1 --- /dev/null +++ b/modules/session/screens/index.php @@ -0,0 +1,5 @@ +