Add method to get all user sessions for a specific user
authorjoshuaruesweg <ruesweg@woltlab.com>
Sat, 24 Oct 2020 14:29:43 +0000 (16:29 +0200)
committerjoshuaruesweg <ruesweg@woltlab.com>
Mon, 2 Nov 2020 11:22:40 +0000 (12:22 +0100)
wcfsetup/install/files/lib/system/session/SessionHandler.class.php

index 5dad6eb8de173da4ffaeaa96073d4cbd28a9323a..9149a5415b2d7cc6daf80165d20569da353d2d7e 100644 (file)
@@ -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.