Merged the log pages into one.
This commit is contained in:
parent
e5335e5274
commit
3cd7a0699e
5 changed files with 86 additions and 78 deletions
|
@ -23,8 +23,7 @@ if (!$app->hasActiveSession()) {
|
|||
$settingsModes = [
|
||||
'account' => 'Account',
|
||||
'sessions' => 'Sessions',
|
||||
'login-history' => 'Login History',
|
||||
'log' => 'Account Log',
|
||||
'logs' => 'Logs',
|
||||
];
|
||||
$settingsMode = $_GET['m'] ?? key($settingsModes);
|
||||
|
||||
|
@ -338,7 +337,10 @@ switch ($settingsMode) {
|
|||
]);
|
||||
break;
|
||||
|
||||
case 'login-history':
|
||||
case 'logs':
|
||||
$loginAttemptsOffset = max(0, $_GET['lo'] ?? 0);
|
||||
$auditLogOffset = max(0, $_GET['ao'] ?? 0);
|
||||
|
||||
$getLoginAttemptsCount = Database::prepare('
|
||||
SELECT COUNT(`attempt_id`)
|
||||
FROM `msz_login_attempts`
|
||||
|
@ -356,24 +358,15 @@ switch ($settingsMode) {
|
|||
ORDER BY `attempt_id` DESC
|
||||
LIMIT :offset, :take
|
||||
');
|
||||
$getLoginAttempts->bindValue('offset', $queryOffset);
|
||||
$getLoginAttempts->bindValue('take', $queryTake);
|
||||
$getLoginAttempts->bindValue('offset', $loginAttemptsOffset);
|
||||
$getLoginAttempts->bindValue('take', min(20, max(5, $queryTake)));
|
||||
$getLoginAttempts->bindValue('user_id', $app->getUserId());
|
||||
$loginAttempts = $getLoginAttempts->execute() ? $getLoginAttempts->fetchAll() : [];
|
||||
|
||||
$tpl->vars([
|
||||
'user_login_attempts' => $loginAttempts,
|
||||
'login_attempts_offset' => $queryOffset,
|
||||
'login_attempts_take' => $queryTake,
|
||||
'login_attempts_count' => $loginAttemptsCount,
|
||||
]);
|
||||
break;
|
||||
|
||||
case 'log':
|
||||
$auditLogCount = audit_log_count($app->getUserId());
|
||||
$auditLog = audit_log_list(
|
||||
$queryOffset,
|
||||
max(20, $queryTake),
|
||||
$auditLogOffset,
|
||||
min(20, max(5, $queryTake)),
|
||||
$app->getUserId()
|
||||
);
|
||||
|
||||
|
@ -381,7 +374,7 @@ switch ($settingsMode) {
|
|||
'audit_logs' => $auditLog,
|
||||
'audit_log_count' => $auditLogCount,
|
||||
'audit_log_take' => $queryTake,
|
||||
'audit_log_offset' => $queryOffset,
|
||||
'audit_log_offset' => $auditLogOffset,
|
||||
'log_strings' => [
|
||||
'PERSONAL_EMAIL_CHANGE' => 'Changed e-mail address to %s.',
|
||||
'PERSONAL_PASSWORD_CHANGE' => 'Changed account password.',
|
||||
|
@ -396,6 +389,10 @@ switch ($settingsMode) {
|
|||
'CHANGELOG_ACTION_CREATE' => 'Created new changelog action #%d.',
|
||||
'CHANGELOG_ACTION_EDITl' => 'Edited changelog action #%d.',
|
||||
],
|
||||
'user_login_attempts' => $loginAttempts,
|
||||
'login_attempts_offset' => $loginAttemptsOffset,
|
||||
'login_attempts_take' => $queryTake,
|
||||
'login_attempts_count' => $loginAttemptsCount,
|
||||
]);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -364,7 +364,7 @@ function url_construct(string $path, array $query = [], string $host = ''): stri
|
|||
$url = $host . $path;
|
||||
|
||||
if (count($query)) {
|
||||
$url .= '?';
|
||||
$url .= strpos($path, '?') !== false ? '&' : '?';
|
||||
|
||||
foreach ($query as $key => $value) {
|
||||
if ($value) {
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
{% macro pagination_class(className, classPrefix) %}{{ className }}{% if classPrefix|length > 0 %} {{ classPrefix ~ className }}{% endif %}{% endmacro %}
|
||||
|
||||
{% macro pagination(itemCount, itemRange, currentOffset, baseUrl, classPrefix, alwaysRender, useRanges, offsetParam, pageRange) %}
|
||||
{% macro pagination(itemCount, itemRange, currentOffset, baseUrl, classPrefix, alwaysRender, offsetParam, useRanges, pageRange) %}
|
||||
{% set alwaysRender = alwaysRender|default(false) %}
|
||||
|
||||
{% if alwaysRender or itemCount > itemRange %}
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
{% extends '@mio/settings/master.twig' %}
|
||||
{% from '@mio/macros.twig' import pagination %}
|
||||
|
||||
{% set alpagination = pagination(audit_log_count, audit_log_take, audit_log_offset, '?m=log', 'settings__') %}
|
||||
|
||||
{% block settings_content %}
|
||||
<div class="container">
|
||||
<div class="container__title">Account Log</div>
|
||||
|
||||
<div class="settings__log">
|
||||
<div class="settings__description">
|
||||
<p>This is a log of all "important" actions that have been done using your account for your review. If you notice anything strange, please alert the staff.</p>
|
||||
</div>
|
||||
|
||||
{{ alpagination }}
|
||||
|
||||
{% for log in audit_logs %}
|
||||
<div class="settings__log__entry" id="log-{{ log.log_id }}">
|
||||
<div class="settings__log__column settings__login-history__column--ip">
|
||||
<div class="settings__log__column__name">
|
||||
IP
|
||||
</div>
|
||||
<div class="settings__log__column__value">
|
||||
{{ log.log_ip }}
|
||||
{% if log.log_country|default('XX') != 'XX' %}
|
||||
<img class="settings__log__country" src="https://static.flash.moe/flags/fff/{{ log.log_country|lower }}.png" alt="{{ log.log_country }}" title="{{ log.log_country|country_name }}">
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="settings__log__column settings__log__column--date" title="{{ log.log_created|date('r') }}">
|
||||
<div class="settings__log__column__name">
|
||||
Date
|
||||
</div>
|
||||
<time class="settings__log__column__value" datetime="{{ log.log_created|date('c') }}">
|
||||
{{ log.log_created|time_diff }}
|
||||
</time>
|
||||
</div>
|
||||
|
||||
<div class="settings__log__column settings__log__column--action">
|
||||
<div class="settings__log__column__name">
|
||||
Action
|
||||
</div>
|
||||
<div class="settings__log__column__value">
|
||||
{% if log.log_action in log_strings|keys %}
|
||||
{{ log_strings[log.log_action]|vsprintf(log.log_params|json_decode) }}
|
||||
{% else %}
|
||||
{{ log.log_action }}({{ log.log_params }})
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
{{ alpagination }}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -1,7 +1,24 @@
|
|||
{% extends '@mio/settings/master.twig' %}
|
||||
{% from '@mio/macros.twig' import pagination %}
|
||||
|
||||
{% set lhpagination = pagination(login_attempts_count, login_attempts_take, login_attempts_offset, '?m=login-history', 'settings__') %}
|
||||
{% set alpagination = pagination(
|
||||
audit_log_count,
|
||||
audit_log_take,
|
||||
audit_log_offset,
|
||||
'?m=logs'|url_construct({'lo': login_attempts_offset}),
|
||||
'settings__',
|
||||
false,
|
||||
'ao'
|
||||
) %}
|
||||
{% set lhpagination = pagination(
|
||||
login_attempts_count,
|
||||
login_attempts_take,
|
||||
login_attempts_offset,
|
||||
'?m=logs'|url_construct({'ao': audit_log_offset}),
|
||||
'settings__',
|
||||
false,
|
||||
'lo'
|
||||
) %}
|
||||
|
||||
{% block settings_content %}
|
||||
<div class="container">
|
||||
|
@ -62,4 +79,56 @@
|
|||
{{ lhpagination }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<div class="container__title">Account Log</div>
|
||||
|
||||
<div class="settings__log">
|
||||
<div class="settings__description">
|
||||
<p>This is a log of all "important" actions that have been done using your account for your review. If you notice anything strange, please alert the staff.</p>
|
||||
</div>
|
||||
|
||||
{{ alpagination }}
|
||||
|
||||
{% for log in audit_logs %}
|
||||
<div class="settings__log__entry" id="log-{{ log.log_id }}">
|
||||
<div class="settings__log__column settings__login-history__column--ip">
|
||||
<div class="settings__log__column__name">
|
||||
IP
|
||||
</div>
|
||||
<div class="settings__log__column__value">
|
||||
{{ log.log_ip }}
|
||||
{% if log.log_country|default('XX') != 'XX' %}
|
||||
<img class="settings__log__country" src="https://static.flash.moe/flags/fff/{{ log.log_country|lower }}.png" alt="{{ log.log_country }}" title="{{ log.log_country|country_name }}">
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="settings__log__column settings__log__column--date" title="{{ log.log_created|date('r') }}">
|
||||
<div class="settings__log__column__name">
|
||||
Date
|
||||
</div>
|
||||
<time class="settings__log__column__value" datetime="{{ log.log_created|date('c') }}">
|
||||
{{ log.log_created|time_diff }}
|
||||
</time>
|
||||
</div>
|
||||
|
||||
<div class="settings__log__column settings__log__column--action">
|
||||
<div class="settings__log__column__name">
|
||||
Action
|
||||
</div>
|
||||
<div class="settings__log__column__value">
|
||||
{% if log.log_action in log_strings|keys %}
|
||||
{{ log_strings[log.log_action]|vsprintf(log.log_params|json_decode) }}
|
||||
{% else %}
|
||||
{{ log.log_action }}({{ log.log_params }})
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
{{ alpagination }}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
Loading…
Add table
Reference in a new issue