Adds property to easily set if a page/action required login
authorMatthias Schmidt <gravatronics@live.com>
Tue, 7 Aug 2012 20:09:12 +0000 (22:09 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Tue, 7 Aug 2012 20:09:12 +0000 (22:09 +0200)
wcfsetup/install/files/lib/action/AbstractAction.class.php
wcfsetup/install/files/lib/page/AbstractPage.class.php

index 40ab568313371e6cf3d18eb234a2185ec7503d2b..715cf0def51bfd15984b8f74c69c35d2e65f19ee 100644 (file)
@@ -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<string>
@@ -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) {
index 53c9231255ea4f0d019db8d18bff04e1cb41cb2c..2aaeea5e176912dc94298f76493b8563d78be607 100644 (file)
@@ -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<string>
@@ -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();