From: joshuaruesweg Date: Sat, 24 Oct 2020 14:29:43 +0000 (+0200) Subject: Add method to get all user sessions for a specific user X-Git-Tag: 5.4.0_Alpha_1~656^2~19 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a8a388cff87c4a674b3f9c26a8d429df9dfc3de2;p=GitHub%2FWoltLab%2FWCF.git Add method to get all user sessions for a specific user --- 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.