From a8a388cff87c4a674b3f9c26a8d429df9dfc3de2 Mon Sep 17 00:00:00 2001 From: joshuaruesweg Date: Sat, 24 Oct 2020 16:29:43 +0200 Subject: [PATCH] Add method to get all user sessions for a specific user --- .../lib/system/session/SessionHandler.class.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php index 5dad6eb8de..9149a5415b 100644 --- a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php +++ b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php @@ -985,6 +985,23 @@ final class SessionHandler extends SingletonFactory { return $this->firstVisit; } + /** + * Returns all user sessions for a specific user. + */ + public function getUserSessions(User $user): array { + if ($user->userID === 0) { + throw new \InvalidArgumentException("The given user is a guest."); + } + + $sql = "SELECT * + FROM wcf".WCF_N."_user_session + WHERE userID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute([$user->userID]); + + return $statement->fetchAll(); + } + /** * Deletes the user sessions for a specific user, except the session with the given session id. * If the given session id is null or unknown, all sessions for the user will be deleted. -- 2.20.1