/** * Logs a user out * @method logout * @static */ static function logout() { // Access the session, if we haven't already. $user = self::loggedInUser(); $sessionId = Q_Session::id(); // One last chance to do something. // Hooks shouldn't be able to cancel the logout. /** * @event Users/logout {before} * @param {Users_User} user */ Q::event('Users/logout', compact('user'), 'before'); $deviceId = isset($_SESSION['Users']['deviceId']) ? $_SESSION['Users']['deviceId'] : null; if ($user) { Q_Utils::sendToNode(array("Q/method" => "Users/logout", "sessionId" => Q_Session::id(), "userId" => $user->id, "deviceId" => $deviceId)); // forget the device for this user/session Users_Device::delete()->where(array('userId' => $user->id, 'sessionId' => $sessionId))->execute(); } // Destroy the current session, which clears the $_SESSION and all notices, etc. Q_Session::destroy(); }