diff --git a/database/2018_10_29_201419_undo_laravel_damage.php b/database/2018_10_29_201419_undo_laravel_damage.php index 735bac3e..7cd0a882 100644 --- a/database/2018_10_29_201419_undo_laravel_damage.php +++ b/database/2018_10_29_201419_undo_laravel_damage.php @@ -54,4 +54,7 @@ function migrate_up(PDO $conn): void function migrate_down(PDO $conn): void { + // can't be bothered to write a reverse for this migration + // honestly i might just remove migrate_down system since i don't really ever use it + $conn = $conn; // trick phpcs } diff --git a/misuzu.php b/misuzu.php index 9b614068..f26af397 100644 --- a/misuzu.php +++ b/misuzu.php @@ -89,7 +89,7 @@ if (PHP_SAPI === 'cli') { // Ensure main role exists. db_exec(" INSERT IGNORE INTO `msz_roles` - (`role_id`, `role_name`, `role_hierarchy`, `role_colour`, `role_description`, `created_at`) + (`role_id`, `role_name`, `role_hierarchy`, `role_colour`, `role_description`, `role_created`) VALUES (1, 'Member', 1, 1073741824, NULL, NOW()) "); @@ -142,7 +142,7 @@ if (PHP_SAPI === 'cli') { // Cleans up the login history table db_exec(' DELETE FROM `msz_login_attempts` - WHERE `created_at` < NOW() - INTERVAL 1 YEAR + WHERE `attempt_created` < NOW() - INTERVAL 1 YEAR '); // Cleans up the audit log table diff --git a/public/auth.php b/public/auth.php index 691de59d..77316e46 100644 --- a/public/auth.php +++ b/public/auth.php @@ -268,7 +268,7 @@ MSG; } user_session_start($userId, $sessionKey); - $cookieLife = strtotime(user_session_current('expires_on')); + $cookieLife = strtotime(user_session_current('session_expires')); set_cookie_m('uid', $userId, $cookieLife); set_cookie_m('sid', $sessionKey, $cookieLife); diff --git a/public/index.php b/public/index.php index 93ea2d6b..5c53b8a9 100644 --- a/public/index.php +++ b/public/index.php @@ -20,7 +20,7 @@ $statistics = cache_get('index:stats:v1', function () { ')->fetchColumn(), 'lastUser' => db_query(' SELECT - u.`user_id`, u.`username`, u.`created_at`, + u.`user_id`, u.`username`, u.`user_created`, COALESCE(u.`user_colour`, r.`role_colour`) as `user_colour` FROM `msz_users` as u LEFT JOIN `msz_roles` as r @@ -54,8 +54,8 @@ $onlineUsers = cache_get('index:online:v1', function () { FROM `msz_users` as u LEFT JOIN `msz_roles` as r ON r.`role_id` = u.`display_role` - WHERE u.`last_seen` >= DATE_SUB(NOW(), INTERVAL 5 MINUTE) - ORDER BY u.`last_seen` DESC + WHERE u.`user_active` >= DATE_SUB(NOW(), INTERVAL 5 MINUTE) + ORDER BY u.`user_active` DESC ')->fetchAll(PDO::FETCH_ASSOC); }, 30); diff --git a/public/manage/users.php b/public/manage/users.php index 731341aa..50b1c192 100644 --- a/public/manage/users.php +++ b/public/manage/users.php @@ -376,12 +376,12 @@ switch ($_GET['v'] ?? null) { INSERT INTO `msz_roles` ( `role_name`, `role_hierarchy`, `role_secret`, `role_colour`, - `role_description`, `created_at`, `role_title` + `role_description`, `role_title` ) VALUES ( :role_name, :role_hierarchy, :role_secret, :role_colour, - :role_description, NOW(), :role_title + :role_description, :role_title ) '); } else { diff --git a/public/members.php b/public/members.php index a1d39cc0..2f0def16 100644 --- a/public/members.php +++ b/public/members.php @@ -31,12 +31,12 @@ $orderFields = [ 'title' => 'Country', ], 'registered' => [ - 'column' => 'created_at', + 'column' => 'user_created', 'default-dir' => 'desc', 'title' => 'Registration Date', ], 'last-online' => [ - 'column' => 'last_seen', + 'column' => 'user_active', 'default-dir' => 'desc', 'title' => 'Last Online', ], @@ -58,7 +58,7 @@ if (empty($orderDir)) { $getRole = db_prepare(' SELECT - `role_id`, `role_name`, `role_colour`, `role_description`, `created_at`, + `role_id`, `role_name`, `role_colour`, `role_description`, `role_created`, ( SELECT COUNT(`user_id`) FROM `msz_user_roles` diff --git a/public/profile.php b/public/profile.php index e67c6e06..03ad82b4 100644 --- a/public/profile.php +++ b/public/profile.php @@ -261,7 +261,7 @@ switch ($mode) { ' SELECT u.`user_id`, u.`username`, u.`user_country`, - u.`created_at`, u.`last_seen`, + u.`user_created`, u.`user_active`, u.`user_about_parser`, u.`user_about_content`, u.`user_background_settings`, %1$s, COALESCE(u.`user_title`, r.`role_title`) as `user_title`, diff --git a/src/Forum/post.php b/src/Forum/post.php index 48cf8d0d..ec763db5 100644 --- a/src/Forum/post.php +++ b/src/Forum/post.php @@ -52,7 +52,7 @@ define('MSZ_FORUM_POST_LISTING_QUERY_STANDARD', ' p.`topic_id`, u.`user_id` as `poster_id`, u.`username` as `poster_name`, - u.`created_at` as `poster_joined`, + u.`user_created` as `poster_joined`, u.`user_country` as `poster_country`, COALESCE(u.`user_colour`, r.`role_colour`) as `poster_colour`, ( diff --git a/src/Users/login_attempt.php b/src/Users/login_attempt.php index 904618ee..0bb44ae1 100644 --- a/src/Users/login_attempt.php +++ b/src/Users/login_attempt.php @@ -3,15 +3,15 @@ function user_login_attempt_record(bool $success, ?int $userId, string $ipAddres { $storeAttempt = db_prepare(' INSERT INTO `msz_login_attempts` - (`was_successful`, `attempt_ip`, `attempt_country`, `user_id`, `user_agent`, `created_at`) + (`attempt_success`, `attempt_ip`, `attempt_country`, `user_id`, `attempt_user_agent`) VALUES - (:was_successful, INET6_ATON(:attempt_ip), :attempt_country, :user_id, :user_agent, NOW()) + (:attempt_success, INET6_ATON(:attempt_ip), :attempt_country, :user_id, :attempt_user_agent) '); - $storeAttempt->bindValue('was_successful', $success ? 1 : 0); + $storeAttempt->bindValue('attempt_success', $success ? 1 : 0); $storeAttempt->bindValue('attempt_ip', $ipAddress); $storeAttempt->bindValue('attempt_country', ip_country_code($ipAddress)); - $storeAttempt->bindValue('user_agent', $userAgent); + $storeAttempt->bindValue('attempt_user_agent', $userAgent); $storeAttempt->bindValue('user_id', $userId, $userId === null ? PDO::PARAM_NULL : PDO::PARAM_INT); $storeAttempt->execute(); } @@ -21,8 +21,8 @@ function user_login_attempts_remaining(string $ipAddress): int $getRemaining = db_prepare(' SELECT 5 - COUNT(`attempt_id`) FROM `msz_login_attempts` - WHERE `was_successful` = false - AND `created_at` > NOW() - INTERVAL 1 HOUR + WHERE `attempt_success` = 0 + AND `attempt_created` > NOW() - INTERVAL 1 HOUR AND `attempt_ip` = INET6_ATON(:remote_ip) '); $getRemaining->bindValue('remote_ip', $ipAddress); @@ -54,7 +54,7 @@ function user_login_attempts_list(int $offset, int $take, int $userId = 0): arra $getAttempts = db_prepare(sprintf(' SELECT - `attempt_id`, `attempt_country`, `was_successful`, `user_agent`, `created_at`, + `attempt_id`, `attempt_country`, `attempt_success`, `attempt_user_agent`, `attempt_created`, INET6_NTOA(`attempt_ip`) as `attempt_ip` FROM `msz_login_attempts` WHERE %s diff --git a/src/Users/session.php b/src/Users/session.php index d7d0cfa4..ffcbca6f 100644 --- a/src/Users/session.php +++ b/src/Users/session.php @@ -13,18 +13,18 @@ function user_session_create( INSERT INTO `msz_sessions` ( `user_id`, `session_ip`, `session_country`, - `user_agent`, `session_key`, `created_at`, `expires_on` + `session_user_agent`, `session_key`, `session_created`, `session_expires` ) VALUES ( :user_id, INET6_ATON(:session_ip), :session_country, - :user_agent, :session_key, NOW(), NOW() + INTERVAL 1 MONTH + :session_user_agent, :session_key, NOW(), NOW() + INTERVAL 1 MONTH ) '); $createSession->bindValue('user_id', $userId); $createSession->bindValue('session_ip', $ipAddress); $createSession->bindValue('session_country', ip_country_code($ipAddress)); - $createSession->bindValue('user_agent', $userAgent); + $createSession->bindValue('session_user_agent', $userAgent); $createSession->bindValue('session_key', $sessionKey); return $createSession->execute() ? $sessionKey : ''; @@ -39,7 +39,7 @@ function user_session_find($sessionId, bool $byKey = false): array $findSession = db_prepare(sprintf(' SELECT `session_id`, `user_id`, INET6_NTOA(`session_ip`) as `session_ip`, - `session_country`, `user_agent`, `session_key`, `created_at`, `expires_on` + `session_country`, `session_user_agent`, `session_key`, `session_created`, `session_expires`, `session_active` FROM `msz_sessions` WHERE `%s` = :session_id ', $byKey ? 'session_key' : 'session_id')); @@ -95,7 +95,7 @@ function user_session_list(int $offset, int $take, int $userId = 0): array $getSessions = db_prepare(sprintf(' SELECT - `session_id`, `session_country`, `user_agent`, `created_at`, `expires_on`, + `session_id`, `session_country`, `session_user_agent`, `session_created`, `session_expires`, `session_active`, INET6_NTOA(`session_ip`) as `session_ip` FROM `msz_sessions` WHERE %s @@ -125,7 +125,7 @@ function user_session_start(int $userId, string $sessionKey): bool return false; } - if (time() >= strtotime($session['expires_on'])) { + if (time() >= strtotime($session['session_expires'])) { user_session_delete($session['session_id']); return false; } @@ -159,5 +159,5 @@ function user_session_current(?string $variable = null, $default = null) function user_session_active(): bool { return !empty($GLOBALS[MSZ_SESSION_DATA_STORE]) - && time() < strtotime($GLOBALS[MSZ_SESSION_DATA_STORE]['expires_on']); + && time() < strtotime($GLOBALS[MSZ_SESSION_DATA_STORE]['session_expires']); } diff --git a/src/Users/user.php b/src/Users/user.php index 9e973368..0a11915f 100644 --- a/src/Users/user.php +++ b/src/Users/user.php @@ -32,12 +32,12 @@ function user_create( INSERT INTO `msz_users` ( `username`, `password`, `email`, `register_ip`, - `last_ip`, `user_country`, `created_at`, `display_role` + `last_ip`, `user_country`, `display_role` ) VALUES ( :username, :password, LOWER(:email), INET6_ATON(:register_ip), - INET6_ATON(:last_ip), :user_country, NOW(), 1 + INET6_ATON(:last_ip), :user_country, 1 ) '); $createUser->bindValue('username', $username); @@ -138,7 +138,7 @@ function user_bump_last_active(int $userId, string $ipAddress = null): void { $bumpUserLast = db_prepare(' UPDATE `msz_users` - SET `last_seen` = NOW(), + SET `user_active` = NOW(), `last_ip` = INET6_ATON(:last_ip) WHERE `user_id` = :user_id '); diff --git a/templates/home/index.twig b/templates/home/index.twig index 4043866f..5948e2a8 100644 --- a/templates/home/index.twig +++ b/templates/home/index.twig @@ -24,7 +24,7 @@ {% else %} We have {{ users_count|number_format }} users and the last person to join was {{ last_user.username }}, - ! + ! {% endif %} diff --git a/templates/manage/users/view.twig b/templates/manage/users/view.twig index 6b02d3f8..3561dd6e 100644 --- a/templates/manage/users/view.twig +++ b/templates/manage/users/view.twig @@ -37,14 +37,14 @@ diff --git a/templates/user/macros.twig b/templates/user/macros.twig index a38eb267..a0e072be 100644 --- a/templates/user/macros.twig +++ b/templates/user/macros.twig @@ -46,7 +46,7 @@ {% macro user_session(session, is_current_session) %} {% from '_layout/input.twig' import input_hidden, input_csrf, input_checkbox_raw %} - {% set browser = get_browser(session.user_agent) %} + {% set browser = get_browser(session.session_user_agent) %}
@@ -80,21 +80,21 @@
-
+
Created
-
-
+
Expires
-
@@ -103,7 +103,7 @@ User Agent
- {{ session.user_agent|length > 0 ? session.user_agent : 'None' }} + {{ session.session_user_agent|length > 0 ? session.session_user_agent : 'None' }}
diff --git a/templates/user/profile.twig b/templates/user/profile.twig index 731f0797..116f0485 100644 --- a/templates/user/profile.twig +++ b/templates/user/profile.twig @@ -11,12 +11,12 @@ { 'title': 'Joined', 'is_date': true, - 'value': profile.created_at, + 'value': profile.user_created, }, { 'title': 'Last seen', 'is_date': true, - 'value': profile.last_seen, + 'value': profile.user_active, }, { 'title': 'Topics', diff --git a/templates/user/settings.twig b/templates/user/settings.twig index 540b5ab4..6eaab920 100644 --- a/templates/user/settings.twig +++ b/templates/user/settings.twig @@ -175,27 +175,27 @@
Was Successful?
-
- {{ attempt.was_successful ? 'Yes' : 'No' }} +
+ {{ attempt.attempt_success ? 'Yes' : 'No' }}
-
+
-
- {% if attempt.user_agent|length > 0 %} + {% if attempt.attempt_user_agent|length > 0 %}
{% endif %}