From 37e99e482717d7e3ba303e135c9342b76b6bb41c Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Tue, 7 Aug 2012 22:09:12 +0200 Subject: [PATCH] Adds property to easily set if a page/action required login --- .../install/files/lib/action/AbstractAction.class.php | 11 +++++++++++ .../install/files/lib/page/AbstractPage.class.php | 11 +++++++++++ 2 files changed, 22 insertions(+) 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(); -- 2.20.1