diff --git a/public/settings.php b/public/settings.php index 338b5582..5c0768ab 100644 --- a/public/settings.php +++ b/public/settings.php @@ -11,31 +11,10 @@ if (!user_session_active()) { $settingsUserId = user_session_current('user_id', 0); -if ($settingsUserId !== user_session_current('user_id', 0) && !user_exists($settingsUserId)) { - echo render_error(400); - return; -} - -$settingsModes = [ - 'account' => 'Account', - 'sessions' => 'Sessions', - 'logs' => 'Logs', -]; -$settingsMode = $_GET['m'] ?? key($settingsModes); - tpl_vars([ 'settings_user_id' => $settingsUserId, - 'settings_mode' => $settingsMode, - 'settings_modes' => $settingsModes, ]); -if (!array_key_exists($settingsMode, $settingsModes)) { - http_response_code(404); - tpl_var('settings_title', 'Not Found'); - echo tpl_render('settings.notfound'); - return; -} - $settingsErrors = []; $disableAccountOptions = !MSZ_DEBUG @@ -163,126 +142,112 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } } } - - if (empty($settingsErrors) && !empty($_POST['user']) && !empty($_SERVER['HTTP_REFERER'])) { - header('Location: /profile.php?u=' . ((int)($_POST['user'] ?? 0))); - return; - } } tpl_vars([ - 'settings_title' => $settingsModes[$settingsMode], 'settings_errors' => $settingsErrors, ]); -switch ($settingsMode) { - case 'account': - $getAccountInfo = db_prepare(sprintf(' - SELECT `email` - FROM `msz_users` - WHERE `user_id` = :user_id - ')); - $getAccountInfo->bindValue('user_id', $settingsUserId); - $accountInfo = $getAccountInfo->execute() ? $getAccountInfo->fetch(PDO::FETCH_ASSOC) : []; +$getAccountInfo = db_prepare(sprintf(' + SELECT `email` + FROM `msz_users` + WHERE `user_id` = :user_id +')); +$getAccountInfo->bindValue('user_id', $settingsUserId); +$accountInfo = $getAccountInfo->execute() ? $getAccountInfo->fetch(PDO::FETCH_ASSOC) : []; - tpl_vars([ - 'background' => $backgroundProps, - 'settings_disable_account_options' => $disableAccountOptions, - 'account_info' => $accountInfo, - ]); - break; +tpl_vars([ + 'background' => $backgroundProps, + 'settings_disable_account_options' => $disableAccountOptions, + 'account_info' => $accountInfo, +]); - case 'sessions': - $getSessionCount = db_prepare(' - SELECT COUNT(`session_id`) - FROM `msz_sessions` - WHERE `user_id` = :user_id - '); - $getSessionCount->bindValue('user_id', $settingsUserId); - $sessionCount = $getSessionCount->execute() ? $getSessionCount->fetchColumn() : 0; +$getSessionCount = db_prepare(' + SELECT COUNT(`session_id`) + FROM `msz_sessions` + WHERE `user_id` = :user_id +'); +$getSessionCount->bindValue('user_id', $settingsUserId); +$sessionCount = $getSessionCount->execute() ? $getSessionCount->fetchColumn() : 0; - $getSessions = db_prepare(' - SELECT - `session_id`, `session_country`, `user_agent`, `created_at`, `expires_on`, - INET6_NTOA(`session_ip`) as `session_ip_decoded` - FROM `msz_sessions` - WHERE `user_id` = :user_id - ORDER BY `session_id` DESC - LIMIT :offset, :take - '); - $getSessions->bindValue('offset', $queryOffset); - $getSessions->bindValue('take', $queryTake); - $getSessions->bindValue('user_id', $settingsUserId); - $sessions = $getSessions->execute() ? $getSessions->fetchAll() : []; +$getSessions = db_prepare(' + SELECT + `session_id`, `session_country`, `user_agent`, `created_at`, `expires_on`, + INET6_NTOA(`session_ip`) as `session_ip_decoded` + FROM `msz_sessions` + WHERE `user_id` = :user_id + ORDER BY `session_id` DESC + LIMIT :offset, :take +'); +$getSessions->bindValue('offset', $queryOffset); +$getSessions->bindValue('take', $queryTake); +$getSessions->bindValue('user_id', $settingsUserId); +$sessions = $getSessions->execute() ? $getSessions->fetchAll() : []; - tpl_vars([ - 'active_session_id' => user_session_current('session_id'), - 'user_sessions' => $sessions, - 'sessions_offset' => $queryOffset, - 'sessions_take' => $queryTake, - 'sessions_count' => $sessionCount, - ]); - break; +tpl_vars([ + 'active_session_id' => user_session_current('session_id'), + 'user_sessions' => $sessions, + 'sessions_offset' => $queryOffset, + 'sessions_take' => $queryTake, + 'sessions_count' => $sessionCount, +]); - case 'logs': - $loginAttemptsOffset = max(0, $_GET['lo'] ?? 0); - $auditLogOffset = max(0, $_GET['ao'] ?? 0); +$loginAttemptsOffset = max(0, $_GET['lo'] ?? 0); +$auditLogOffset = max(0, $_GET['ao'] ?? 0); - $getLoginAttemptsCount = db_prepare(' - SELECT COUNT(`attempt_id`) - FROM `msz_login_attempts` - WHERE `user_id` = :user_id - '); - $getLoginAttemptsCount->bindValue('user_id', $settingsUserId); - $loginAttemptsCount = $getLoginAttemptsCount->execute() ? $getLoginAttemptsCount->fetchColumn() : 0; +$getLoginAttemptsCount = db_prepare(' + SELECT COUNT(`attempt_id`) + FROM `msz_login_attempts` + WHERE `user_id` = :user_id +'); +$getLoginAttemptsCount->bindValue('user_id', $settingsUserId); +$loginAttemptsCount = $getLoginAttemptsCount->execute() ? $getLoginAttemptsCount->fetchColumn() : 0; - $getLoginAttempts = db_prepare(' - SELECT - `attempt_id`, `attempt_country`, `was_successful`, `user_agent`, `created_at`, - INET6_NTOA(`attempt_ip`) as `attempt_ip_decoded` - FROM `msz_login_attempts` - WHERE `user_id` = :user_id - ORDER BY `attempt_id` DESC - LIMIT :offset, :take - '); - $getLoginAttempts->bindValue('offset', $loginAttemptsOffset); - $getLoginAttempts->bindValue('take', min(20, max(5, $queryTake))); - $getLoginAttempts->bindValue('user_id', $settingsUserId); - $loginAttempts = $getLoginAttempts->execute() ? $getLoginAttempts->fetchAll() : []; +$getLoginAttempts = db_prepare(' + SELECT + `attempt_id`, `attempt_country`, `was_successful`, `user_agent`, `created_at`, + INET6_NTOA(`attempt_ip`) as `attempt_ip_decoded` + FROM `msz_login_attempts` + WHERE `user_id` = :user_id + ORDER BY `attempt_id` DESC + LIMIT :offset, :take +'); +$getLoginAttempts->bindValue('offset', $loginAttemptsOffset); +$getLoginAttempts->bindValue('take', min(20, max(5, $queryTake))); +$getLoginAttempts->bindValue('user_id', $settingsUserId); +$loginAttempts = $getLoginAttempts->execute() ? $getLoginAttempts->fetchAll() : []; - $auditLogCount = audit_log_count($settingsUserId); - $auditLog = audit_log_list( - $auditLogOffset, - min(20, max(5, $queryTake)), - $settingsUserId - ); +$auditLogCount = audit_log_count($settingsUserId); +$auditLog = audit_log_list( + $auditLogOffset, + min(20, max(5, $queryTake)), + $settingsUserId +); - tpl_vars([ - 'audit_logs' => $auditLog, - 'audit_log_count' => $auditLogCount, - 'audit_log_take' => $queryTake, - 'audit_log_offset' => $auditLogOffset, - 'log_strings' => [ - 'PERSONAL_EMAIL_CHANGE' => 'Changed e-mail address to %s.', - 'PERSONAL_PASSWORD_CHANGE' => 'Changed account password.', - 'PERSONAL_SESSION_DESTROY' => 'Ended session #%d.', - 'PERSONAL_SESSION_DESTROY_ALL' => 'Ended all personal sessions.', - 'PASSWORD_RESET' => 'Successfully used the password reset form to change password.', - 'CHANGELOG_ENTRY_CREATE' => 'Created a new changelog entry #%d.', - 'CHANGELOG_ENTRY_EDIT' => 'Edited changelog entry #%d.', - 'CHANGELOG_TAG_ADD' => 'Added tag #%2$d to changelog entry #%1$d.', - 'CHANGELOG_TAG_REMOVE' => 'Removed tag #%2$d from changelog entry #%1$d.', - 'CHANGELOG_TAG_CREATE' => 'Created new changelog tag #%d.', - 'CHANGELOG_TAG_EDIT' => 'Edited changelog tag #%d.', - 'CHANGELOG_ACTION_CREATE' => 'Created new changelog action #%d.', - 'CHANGELOG_ACTION_EDIT' => 'Edited changelog action #%d.', - ], - 'user_login_attempts' => $loginAttempts, - 'login_attempts_offset' => $loginAttemptsOffset, - 'login_attempts_take' => $queryTake, - 'login_attempts_count' => $loginAttemptsCount, - ]); - break; -} +tpl_vars([ + 'audit_logs' => $auditLog, + 'audit_log_count' => $auditLogCount, + 'audit_log_take' => $queryTake, + 'audit_log_offset' => $auditLogOffset, + 'log_strings' => [ + 'PERSONAL_EMAIL_CHANGE' => 'Changed e-mail address to %s.', + 'PERSONAL_PASSWORD_CHANGE' => 'Changed account password.', + 'PERSONAL_SESSION_DESTROY' => 'Ended session #%d.', + 'PERSONAL_SESSION_DESTROY_ALL' => 'Ended all personal sessions.', + 'PASSWORD_RESET' => 'Successfully used the password reset form to change password.', + 'CHANGELOG_ENTRY_CREATE' => 'Created a new changelog entry #%d.', + 'CHANGELOG_ENTRY_EDIT' => 'Edited changelog entry #%d.', + 'CHANGELOG_TAG_ADD' => 'Added tag #%2$d to changelog entry #%1$d.', + 'CHANGELOG_TAG_REMOVE' => 'Removed tag #%2$d from changelog entry #%1$d.', + 'CHANGELOG_TAG_CREATE' => 'Created new changelog tag #%d.', + 'CHANGELOG_TAG_EDIT' => 'Edited changelog tag #%d.', + 'CHANGELOG_ACTION_CREATE' => 'Created new changelog action #%d.', + 'CHANGELOG_ACTION_EDIT' => 'Edited changelog action #%d.', + ], + 'user_login_attempts' => $loginAttempts, + 'login_attempts_offset' => $loginAttemptsOffset, + 'login_attempts_take' => $queryTake, + 'login_attempts_count' => $loginAttemptsCount, +]); -echo tpl_render("settings.{$settingsMode}"); +echo tpl_render('user.settings'); diff --git a/templates/macros.twig b/templates/macros.twig index 37fc420a..d10ca8ec 100644 --- a/templates/macros.twig +++ b/templates/macros.twig @@ -77,14 +77,18 @@ {% endif %} {% endmacro %} -{% macro container_title(title, url) %} +{% macro container_title(title, url, raw) %} {% set has_url = url is not null and url|length > 0 %}
{% if has_url %}{% endif %}
- {{ title }} + {% if raw %} + {{ title|raw }} + {% else %} + {{ title }} + {% endif %}
{% if has_url %}
{% endif %}
diff --git a/templates/settings/account.twig b/templates/settings/account.twig deleted file mode 100644 index adbd8420..00000000 --- a/templates/settings/account.twig +++ /dev/null @@ -1,115 +0,0 @@ -{% extends 'settings/master.twig' %} -{% from 'macros.twig' import container_title %} -{% from '_layout/input.twig' import input_hidden, input_csrf, input_text %} - -{% block settings_content %} -
-
- A few of the elements on this page have been moved to the on-profile editor. To find them, go to your profile and hit the "Edit Profile" button below your avatar. -
-
- -
- {{ container_title('Account') }} - -
- {{ input_csrf('settings') }} - - - - {% if not settings_disable_account_options %} - - {% endif %} -
-
-{% endblock %} diff --git a/templates/settings/logs.twig b/templates/settings/logs.twig deleted file mode 100644 index 432e8b40..00000000 --- a/templates/settings/logs.twig +++ /dev/null @@ -1,132 +0,0 @@ -{% extends 'settings/master.twig' %} -{% from 'macros.twig' import pagination, container_title %} - -{% set alpagination = pagination( - audit_log_count, - audit_log_take, - audit_log_offset, - '?m=logs'|url_construct({'lo': login_attempts_offset}), - false, - 'ao' -) %} -{% set lhpagination = pagination( - login_attempts_count, - login_attempts_take, - login_attempts_offset, - '?m=logs'|url_construct({'ao': audit_log_offset}), - false, - 'lo' -) %} - -{% block settings_content %} -
- {{ container_title('Login History') }} - -
-
-

These are all the login attempts to your account. If any attempt that you don't recognise is marked as successful your account may be compromised, ask a staff member for advice in this case.

-
- - {{ lhpagination }} - - {% for attempt in user_login_attempts %} - - {% endfor %} - - {{ lhpagination }} -
-
- -
- {{ container_title('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/templates/settings/master.twig b/templates/settings/master.twig deleted file mode 100644 index df6485d3..00000000 --- a/templates/settings/master.twig +++ /dev/null @@ -1,34 +0,0 @@ -{% extends 'master.twig' %} -{% from 'macros.twig' import navigation, container_title %} - -{% set title = 'Settings ยป ' ~ settings_title %} - -{% block content %} - {{ navigation(settings_modes|flip, settings_mode, true, '?m=%s') }} - - {% block settings_container %} - {% if settings_errors is defined and settings_errors|length > 0 %} -
- {{ container_title('Information') }} - -
- -
-
- {% endif %} - - {% block settings_content %} -
- {{ container_title(title) }} - -
- This is a blank settings page. -
-
- {% endblock %} - {% endblock %} -{% endblock %} diff --git a/templates/settings/notfound.twig b/templates/settings/notfound.twig deleted file mode 100644 index f22b28cb..00000000 --- a/templates/settings/notfound.twig +++ /dev/null @@ -1,5 +0,0 @@ -{% extends 'settings/master.twig' %} - -{% block settings_content %} -

Could not find what you were looking for.

-{% endblock %} diff --git a/templates/settings/sessions.twig b/templates/settings/sessions.twig deleted file mode 100644 index 7f3b84eb..00000000 --- a/templates/settings/sessions.twig +++ /dev/null @@ -1,83 +0,0 @@ -{% extends 'settings/master.twig' %} -{% from 'macros.twig' import pagination, container_title %} -{% from '_layout/input.twig' import input_hidden, input_csrf %} - -{% set spagination = pagination(sessions_count, sessions_take, sessions_offset, '?m=sessions') %} - -{% block settings_content %} -
- {{ container_title('Sessions') }} - -
-
-

These are the active logins to your account, clicking the Kill button will force a logout on that session. Your current login is highlighted with a darker purple so you don't accidentally force yourself to logout.

-
- -
- {{ input_csrf('settings') }} - - -
- - {{ spagination }} - - {% for session in user_sessions %} -
-
-
- IP -
-
- {{ session.session_ip_decoded }} - {% if session.session_country != 'XX' %} -
- {% endif %} -
-
- -
-
- Created -
- -
- -
-
- Expires -
- -
- - {% if session.user_agent|length > 0 %} -
-
- User Agent -
-
- {{ session.user_agent }} -
-
- {% endif %} - -
- {{ input_hidden('session', session.session_id) }} - {{ input_csrf('settings') }} - - -
-
- {% endfor %} - - {{ spagination }} -
-
-{% endblock %} diff --git a/templates/user/settings.twig b/templates/user/settings.twig new file mode 100644 index 00000000..d3e5c30b --- /dev/null +++ b/templates/user/settings.twig @@ -0,0 +1,335 @@ +{% extends 'user/master.twig' %} +{% from 'macros.twig' import container_title, pagination %} +{% from '_layout/input.twig' import input_hidden, input_csrf, input_text %} + +{% set title = 'Settings' %} + +{% block content %} + {% if settings_errors is defined and settings_errors|length > 0 %} +
+
+ {% for error in settings_errors %} + {{ error }} + {% endfor %} +
+
+ {% else %} +
+
+ A few of the elements on this page have been moved to the on-profile editor. To find them, go to your profile and hit the "Edit Profile" button below your avatar. +
+
+ {% endif %} + +
+ {{ container_title(' Account', '', true) }} + +
+

Here you can change your e-mail address and/or your password, please make sure your e-mail is accurate and your password is strong in order to protect your account. For convenience your current e-mail address is displayed.

+
+ +
+ {{ input_csrf('settings') }} + + + + {% if not settings_disable_account_options %} + + {% endif %} +
+
+ +
+ {{ container_title(' Sessions', '', true) }} + {% set spagination = pagination(sessions_count, sessions_take, sessions_offset, '?m=sessions') %} + +
+

These are the active logins to your account, clicking the Kill button will force a logout on that session. Your current login is highlighted with a darker purple so you don't accidentally force yourself to logout.

+
+ +
+
+ {{ input_csrf('settings') }} + + +
+ + {{ spagination }} + + {% for session in user_sessions %} +
+
+
+ IP +
+
+ {{ session.session_ip_decoded }} + {% if session.session_country != 'XX' %} +
+ {% endif %} +
+
+ +
+
+ Created +
+ +
+ +
+
+ Expires +
+ +
+ + {% if session.user_agent|length > 0 %} +
+
+ User Agent +
+
+ {{ session.user_agent }} +
+
+ {% endif %} + +
+ {{ input_hidden('session', session.session_id) }} + {{ input_csrf('settings') }} + + +
+
+ {% endfor %} + + {{ spagination }} +
+
+ +
+ {{ container_title(' Login History', '', true) }} + {% set lhpagination = pagination( + login_attempts_count, + login_attempts_take, + login_attempts_offset, + '?m=logs'|url_construct({'ao': audit_log_offset}), + false, + 'lo' + ) %} + +
+
+

These are all the login attempts to your account. If any attempt that you don't recognise is marked as successful your account may be compromised, ask a staff member for advice in this case.

+
+ + {{ lhpagination }} + + {% for attempt in user_login_attempts %} + + {% endfor %} + + {{ lhpagination }} +
+
+ +
+ {{ container_title(' Account Log', '', true) }} + {% set alpagination = pagination( + audit_log_count, + audit_log_take, + audit_log_offset, + '?m=logs'|url_construct({'lo': login_attempts_offset}), + false, + 'ao' + ) %} + +
+
+

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 %}