From: Matthias Schmidt Date: Tue, 7 Aug 2012 20:09:12 +0000 (+0200) Subject: Adds property to easily set if a page/action required login X-Git-Tag: 2.0.0_Beta_1~887^2~9^2^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=37e99e482717d7e3ba303e135c9342b76b6bb41c;p=GitHub%2FWoltLab%2FWCF.git Adds property to easily set if a page/action required login --- diff --git a/wcfsetup/install/files/lib/action/AbstractAction.class.php b/wcfsetup/install/files/lib/action/AbstractAction.class.php index 40ab568313..715cf0def5 100644 --- a/wcfsetup/install/files/lib/action/AbstractAction.class.php +++ b/wcfsetup/install/files/lib/action/AbstractAction.class.php @@ -16,6 +16,12 @@ use wcf\system\WCF; * @category Community Framework */ abstract class AbstractAction implements IAction { + /** + * indicates if you need to be logged in to execute this action + * @var boolean + */ + public $loginRequired = false; + /** * needed modules to execute this action * @var array @@ -54,6 +60,11 @@ abstract class AbstractAction implements IAction { * @see wcf\action\IAction::execute() */ public function execute() { + // check if active user is logged in + if ($this->loginRequired && !WCF::getUser()->userID) { + throw new PermissionDeniedException(); + } + // check modules if (count($this->neededModules)) { foreach ($this->neededModules as $module) { diff --git a/wcfsetup/install/files/lib/page/AbstractPage.class.php b/wcfsetup/install/files/lib/page/AbstractPage.class.php index 53c9231255..2aaeea5e17 100644 --- a/wcfsetup/install/files/lib/page/AbstractPage.class.php +++ b/wcfsetup/install/files/lib/page/AbstractPage.class.php @@ -35,6 +35,12 @@ abstract class AbstractPage implements IPage { */ public $action = ''; + /** + * indicates if you need to be logged in to access this page + * @var boolean + */ + public $loginRequired = false; + /** * needed modules to view this page * @var array @@ -138,6 +144,11 @@ abstract class AbstractPage implements IPage { * @see wcf\page\IPage::show() */ public function show() { + // check if active user is logged in + if ($this->loginRequired && !WCF::getUser()->userID) { + throw new PermissionDeniedException(); + } + // check modules $this->checkModules();