diff --git a/misuzu.php b/misuzu.php index 97b9a6c4..80823891 100644 --- a/misuzu.php +++ b/misuzu.php @@ -276,15 +276,7 @@ MIG; $app->startSession((int)$_COOKIE['msz_uid'], $_COOKIE['msz_sid']); if ($app->hasActiveSession()) { - $bumpUserLast = Database::prepare(' - UPDATE `msz_users` SET - `last_seen` = NOW(), - `last_ip` = INET6_ATON(:last_ip) - WHERE `user_id` = :user_id - '); - $bumpUserLast->bindValue('last_ip', Net\IPAddress::remote()->getString()); - $bumpUserLast->bindValue('user_id', $app->getUserId()); - $bumpUserLast->execute(); + user_bump_last_active($app->getUserId()); $getUserDisplayInfo = Database::prepare(' SELECT diff --git a/src/Users/user.php b/src/Users/user.php index 402353af..0251b5d5 100644 --- a/src/Users/user.php +++ b/src/Users/user.php @@ -69,6 +69,19 @@ function user_id_from_username(string $username): int return $getId->execute() ? (int)$getId->fetchColumn() : 0; } +function user_bump_last_active(int $userId, string $ipAddress = null): void +{ + $bumpUserLast = Database::prepare(' + UPDATE `msz_users` + SET `last_seen` = NOW(), + `last_ip` = INET6_ATON(:last_ip) + WHERE `user_id` = :user_id + '); + $bumpUserLast->bindValue('last_ip', $ipAddress ?? $_SERVER['REMOTE_ADDR'] ?? '::1'); + $bumpUserLast->bindValue('user_id', $userId); + $bumpUserLast->execute(); +} + define('MSZ_USER_AVATAR_FORMAT', '%d.msz'); function user_avatar_delete(int $userId): void