Skip to content

Commit

Permalink
GH-150 Move login page's display logic to a separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Feb 4, 2021
1 parent 3a519c2 commit 367cb56
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 22 deletions.
26 changes: 4 additions & 22 deletions login.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'][] = (
"<a href='?lang={$langKey}' title='{$langData['name']}'>" .
"{$langData['flag_emoji']}" .
"</a>"
);
}
$_Lang['PHP_Insert_LangSelectors'] = implode('&nbsp;&nbsp;', $_Lang['PHP_Insert_LangSelectors']);
$pageView = Session\Screens\LoginView\render([]);

if($_GameConfig['game_disable'])
{
$_Lang['type'] = 'button" onclick="alert(\''.str_replace('<br/>', "\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']);

?>
14 changes: 14 additions & 0 deletions modules/session/_includes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

// TODO: Migrate to IIFE once PHP 5 support is removed
call_user_func(function () {
global $_EnginePath;

$includePath = $_EnginePath . 'modules/session/';

include($includePath . './screens/LoginView/LoginView.component.php');
include($includePath . './screens/LoginView/components/LoginForm/LoginForm.component.php');

});

?>
5 changes: 5 additions & 0 deletions modules/session/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>
33 changes: 33 additions & 0 deletions modules/session/screens/LoginView/LoginView.component.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace UniEngine\Engine\Modules\Session\Screens\LoginView;

// Arguments
// - $props (Object)
//
// Returns: Object
// - componentHTML (String)
//
function render ($props) {
includeLang('login');

// Handle user input
// $cmdResult = Session\Input\UserCommands\handleCommands(
// $input,
// []
// );
// if ($cmdResult['isSuccess']) {
// // TODO: do something
// } else {
// // TODO: collect errors to display
// }

$viewProps = [];
$viewComponent = Components\LoginForm\render($viewProps);

return [
'componentHTML' => $viewComponent['componentHTML'],
];
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace UniEngine\Engine\Modules\Session\Screens\LoginView\Components\LoginForm;

// Arguments
// - $props (Object)
//
// Returns: Object
// - componentHTML (String)
//
function render ($props) {
global $_Lang, $_GameConfig;

$localTemplateLoader = createLocalTemplateLoader(__DIR__);

$tplBodyCache = [
'pageBody' => $localTemplateLoader('form_body'),
];

$renderLangSelectorOptions = function () use ($_Lang) {
$options = [];

foreach (UNIENGINE_LANGS_AVAILABLE as $langKey) {
$langData = $_Lang['LanguagesAvailable'][$langKey];

$options[] = (
"<a href='?lang={$langKey}' title='{$langData['name']}'>" .
"{$langData['flag_emoji']}" .
"</a>"
);
}

return implode('&nbsp;&nbsp;', $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('<br/>', "\n", $gameDisabledReason) . '\')' :
'submit'
),
'LoginButton' => (
$isGameDisabled ?
$_Lang['Body_ServerOffline'] :
$_Lang['Body_Submit']
),
];

$componentHTML = parsetemplate(
$tplBodyCache['pageBody'],
array_merge(
$_Lang,
$additionalTplData
)
);

return [
'componentHTML' => $componentHTML
];
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<form action="" method="post">
<input type="hidden" name="uniSelect" value="{PHP_InsertUniCode}"/>
<table width="500" style="margin-top: 100px;">
<tr>
<td class="c center" colspan="2">{Page_Title}</td>
</tr>
<tr>
<th class="pad5" style="width: 200px;"><label for="uname">{Body_Username}:</label></th>
<th class="pad5"><input id="uname" name="username" value="" type="text" class="pad5" style="width: 200px;"/></th>
</tr>
<tr>
<th class="pad5" style="width: 200px;"><label for="upass">{Body_Password}:</label></th>
<th class="pad5"><input id="upass" name="password" value="" type="password" class="pad5" style="width: 200px;"/></th>
</tr>
<tr>
<th colspan="2" class="pad5"><input type="{type}" name="submit" value="{LoginButton}" style="width: 100%; font-weight: bold;" class="pad5 lime"/></th>
</tr>
<tr style="visibility: hidden;"><td style="font-size: 5px;">&nbsp;</td></tr>
<tr>
<th colspan="2" class="pad5"><a href="lostpassword.php">{Body_LostPass}</a><br /><a href="lostcode.php">{Body_LostCode}</a></th>
</tr>
<tr>
<th colspan="2" class="pad5">
<a href="reg_mainpage.php">{Body_Register}</a> | <a href="contact.php">{Body_Contact}</a>
</th>
</tr>
<tr style="visibility: hidden;"><td style="font-size: 5px;">&nbsp;</td></tr>
<tr>
<th colspan="2" class="pad5">
{PHP_Insert_LangSelectors}
</th>
</tr>
<tr style="visibility: hidden;"><td style="font-size: 5px;">&nbsp;</td></tr>
<tr>
<th colspan="2" class="pad5">
<a href="https://github.com/mdziekon/UniEngine" target="_blank" class="skyblue">Powered by UniEngine</a>
</th>
</tr>
</table>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>
5 changes: 5 additions & 0 deletions modules/session/screens/LoginView/components/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>
5 changes: 5 additions & 0 deletions modules/session/screens/LoginView/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>
5 changes: 5 additions & 0 deletions modules/session/screens/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>

0 comments on commit 367cb56

Please sign in to comment.