-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-224 Move login entry rendering into a component
- Loading branch information
Showing
6 changed files
with
148 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
modules/settings/components/LoginHistoryEntry/LoginHistoryEntry.component.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
namespace UniEngine\Engine\Modules\Settings\Components\LoginHistoryEntry; | ||
|
||
use UniEngine\Engine\Includes\Helpers\Common\Collections; | ||
|
||
/** | ||
* @param object $props | ||
* @param object $props['entryData'] | ||
* @param string $props['userLastIp'] | ||
* @param number $props['currentTimestamp'] | ||
* | ||
* @return object $result | ||
* @return string $result['componentHTML'] | ||
*/ | ||
function render($props) { | ||
global $_Lang; | ||
|
||
$entryData = $props['entryData']; | ||
$userLastIp = $props['userLastIp']; | ||
$currentTimestamp = $props['currentTimestamp']; | ||
|
||
$localTemplateLoader = createLocalTemplateLoader(__DIR__); | ||
|
||
$tplBodyCache = [ | ||
'body' => $localTemplateLoader('body'), | ||
]; | ||
|
||
$isSuccessfulLogin = ($entryData['State'] === true); | ||
$isSameIpAsLastSeen = ($entryData['IP'] == $userLastIp); | ||
|
||
$dateColorClassNames = Collections\compact([ | ||
( | ||
( | ||
!$isSuccessfulLogin && | ||
!$isSameIpAsLastSeen | ||
) ? | ||
'red' : | ||
null | ||
) | ||
]); | ||
$ipColorClassNames = Collections\compact([ | ||
( | ||
$isSuccessfulLogin ? | ||
'lime' : | ||
null | ||
), | ||
( | ||
( | ||
!$isSuccessfulLogin && | ||
!$isSameIpAsLastSeen | ||
) ? | ||
'red' : | ||
null | ||
) | ||
]); | ||
$stateColorClassNames = Collections\compact([ | ||
( | ||
( | ||
!$isSuccessfulLogin && | ||
!$isSameIpAsLastSeen | ||
) ? | ||
'red' : | ||
null | ||
), | ||
( | ||
( | ||
!$isSuccessfulLogin && | ||
$isSameIpAsLastSeen | ||
) ? | ||
'orange' : | ||
null | ||
) | ||
]); | ||
|
||
$dateColorClassName = reset($dateColorClassNames); | ||
$ipColorClassName = reset($ipColorClassNames); | ||
$stateColorClassName = reset($stateColorClassNames); | ||
|
||
$componentTplData = [ | ||
'inject_dateColorClass' => $dateColorClassName, | ||
'inject_ipColorClass' => $ipColorClassName, | ||
'inject_stateColorClass' => $stateColorClassName, | ||
'data_loginTimeAbsolute' => prettyDate('d m Y, H:i:s', $entryData['Time'], 1), | ||
'data_loginTimeRelative' => implode( | ||
' ', | ||
[ | ||
pretty_time($currentTimestamp - $entryData['Time'], true, 'D'), | ||
$_Lang['Logons_ago'] | ||
] | ||
), | ||
'data_ip' => $entryData['IP'], | ||
'data_stateLabel' => ( | ||
$isSuccessfulLogin ? | ||
$_Lang['Logons_Success'] : | ||
$_Lang['Logons_Failed'] | ||
), | ||
]; | ||
|
||
$componentHTML = parsetemplate( | ||
$tplBodyCache['body'], | ||
$componentTplData | ||
); | ||
|
||
return [ | ||
'componentHTML' => $componentHTML | ||
]; | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<tr class="logon"> | ||
<th class="{inject_dateColorClass}"> | ||
{data_loginTimeAbsolute} | ||
</th> | ||
<th class="{inject_dateColorClass}"> | ||
{data_loginTimeRelative} | ||
</th> | ||
<th class="{inject_ipColorClass}"> | ||
{data_ip} | ||
</th> | ||
<th class="{inject_stateColorClass}"> | ||
{data_stateLabel} | ||
</th> | ||
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
header("Location: ../index.php"); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
header("Location: ../index.php"); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters