diff --git a/public/settings.php b/public/settings.php index 55bc972e..db965418 100644 --- a/public/settings.php +++ b/public/settings.php @@ -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; } diff --git a/utility.php b/utility.php index bcc7e59a..4f9b9311 100644 --- a/utility.php +++ b/utility.php @@ -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) { diff --git a/views/mio/macros.twig b/views/mio/macros.twig index 3fcde997..2218476a 100644 --- a/views/mio/macros.twig +++ b/views/mio/macros.twig @@ -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 %} diff --git a/views/mio/settings/log.twig b/views/mio/settings/log.twig deleted file mode 100644 index 0fd55677..00000000 --- a/views/mio/settings/log.twig +++ /dev/null @@ -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 %} -
-
Account Log
- -
-
-

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.

-
- - {{ alpagination }} - - {% for log in audit_logs %} -
- - -
-
- Date -
- -
- -
-
- Action -
-
- {% 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 %} -
-
-
- {% endfor %} - - {{ alpagination }} -
-
-{% endblock %} diff --git a/views/mio/settings/login-history.twig b/views/mio/settings/logs.twig similarity index 53% rename from views/mio/settings/login-history.twig rename to views/mio/settings/logs.twig index 82e3be41..4e6ebddf 100644 --- a/views/mio/settings/login-history.twig +++ b/views/mio/settings/logs.twig @@ -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 %}
@@ -62,4 +79,56 @@ {{ lhpagination }}
+ +
+
Account Log
+ +
+
+

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.

+
+ + {{ alpagination }} + + {% for log in audit_logs %} +
+ + +
+
+ Date +
+ +
+ +
+
+ Action +
+
+ {% 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 %} +
+
+
+ {% endfor %} + + {{ alpagination }} +
+
{% endblock %}