diff --git a/modules/settings/_includes.php b/modules/settings/_includes.php index b7d8bff4..7c6bc812 100644 --- a/modules/settings/_includes.php +++ b/modules/settings/_includes.php @@ -6,6 +6,8 @@ $includePath = $_EnginePath . 'modules/settings/'; + include($includePath . './components/LoginHistoryEntry/LoginHistoryEntry.component.php'); + include($includePath . './utils/content/prepareChangeProcessEmails.content.php'); include($includePath . './utils/errorMappers/tryDeleteUserIgnoreEntries.errorMapper.php'); diff --git a/modules/settings/components/LoginHistoryEntry/LoginHistoryEntry.component.php b/modules/settings/components/LoginHistoryEntry/LoginHistoryEntry.component.php new file mode 100644 index 00000000..298acff2 --- /dev/null +++ b/modules/settings/components/LoginHistoryEntry/LoginHistoryEntry.component.php @@ -0,0 +1,110 @@ + $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 + ]; +} + +?> diff --git a/modules/settings/components/LoginHistoryEntry/body.tpl b/modules/settings/components/LoginHistoryEntry/body.tpl new file mode 100644 index 00000000..e1c4757d --- /dev/null +++ b/modules/settings/components/LoginHistoryEntry/body.tpl @@ -0,0 +1,14 @@ + + + {data_loginTimeAbsolute} + + + {data_loginTimeRelative} + + + {data_ip} + + + {data_stateLabel} + + diff --git a/modules/settings/components/LoginHistoryEntry/index.php b/modules/settings/components/LoginHistoryEntry/index.php new file mode 100644 index 00000000..bc99142d --- /dev/null +++ b/modules/settings/components/LoginHistoryEntry/index.php @@ -0,0 +1,5 @@ + diff --git a/modules/settings/components/index.php b/modules/settings/components/index.php new file mode 100644 index 00000000..bc99142d --- /dev/null +++ b/modules/settings/components/index.php @@ -0,0 +1,5 @@ + diff --git a/settings.php b/settings.php index f6f65dd8..b26746c1 100644 --- a/settings.php +++ b/settings.php @@ -1126,44 +1126,25 @@ array_multisort($LogonList, SORT_DESC, $LogonTimes); $LimitCounter = $LogonLIMIT; - foreach($LogonList as $LogonData) - { - if($LimitCounter <= 0) - { + + $_Lang['ParseLogonsList'] = []; + + foreach ($LogonList as $LogonData) { + if ($LimitCounter <= 0) { break; } - if($LogonData['IP'] == $_User['user_lastip']) - { - $LogonData['IPColor'] = 'lime'; - } - if($LogonData['State'] === false) - { - if($LogonData['IP'] != $_User['user_lastip']) - { - $LogonData['DateColor'] = 'red'; - $LogonData['IPColor'] = 'red'; - $LogonData['StateColor'] = 'red'; - } - else - { - $LogonData['StateColor'] = 'orange'; - } - } + $_Lang['ParseLogonsList'][] = Settings\Components\LoginHistoryEntry\render([ + 'entryData' => $LogonData, + 'userLastIp' => $_User['user_lastip'], + 'currentTimestamp' => $Now, + ])['componentHTML']; - $ThisRow = ''; - $ThisRow .= ''.prettyDate('d m Y, H:i:s', $LogonData['Time'], 1).''; - $ThisRow .= ''.pretty_time($Now - $LogonData['Time'], true, 'D').' '.$_Lang['Logons_ago'].''; - $ThisRow .= ''.$LogonData['IP'].''; - $ThisRow .= ''.($LogonData['State'] === true ? $_Lang['Logons_Success'] : $_Lang['Logons_Failed']).''; - $ThisRow .= ''; - $_Lang['ParseLogonsList'][] = $ThisRow; $LimitCounter -= 1; } + $_Lang['ParseLogonsList'] = implode('', $_Lang['ParseLogonsList']); - } - else - { + } else { $_Lang['ParseLogonsList'] = ''.$_Lang['Logons_ListEmpty'].''; }