From: joshuaruesweg Date: Fri, 30 Oct 2020 13:47:19 +0000 (+0100) Subject: Add action to delete an own session X-Git-Tag: 5.4.0_Alpha_1~656^2~5 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=dfc82233c8debbb703c21f1b86946b54691c5a2e;p=GitHub%2FWoltLab%2FWCF.git Add action to delete an own session --- diff --git a/wcfsetup/install/files/lib/action/DeleteSessionAction.class.php b/wcfsetup/install/files/lib/action/DeleteSessionAction.class.php new file mode 100644 index 0000000000..512b31d8a8 --- /dev/null +++ b/wcfsetup/install/files/lib/action/DeleteSessionAction.class.php @@ -0,0 +1,70 @@ + + * @package WoltLabSuite\Core\Action + */ +class DeleteSessionAction extends AbstractAction { + /** + * @inheritDoc + */ + public $loginRequired = true; + + /** + * @var string + */ + public $sessionID; + + /** + * @inheritDoc + */ + public function readParameters() { + parent::readParameters(); + + if (isset($_POST['sessionID'])) $this->sessionID = StringUtil::trim($_POST['sessionID']); + + if (empty($this->sessionID)) { + throw new IllegalLinkException(); + } + + $found = false; + foreach (SessionHandler::getInstance()->getUserSessions(WCF::getUser()) as $session) { + if ($session->getSessionID() === $this->sessionID) { + $found = true; + break; + } + } + + if (!$found) { + throw new IllegalLinkException(); + } + } + + /** + * @inheritDoc + */ + public function execute() { + parent::execute(); + + SessionHandler::getInstance()->deleteUserSession($this->sessionID); + + $this->executed(); + + // send JSON-encoded response + header('Content-type: application/json'); + echo JSON::encode([ + 'sessionID' => $this->sessionID, + ]); + exit; + } +}