From 25c3c49665cd853fd9618426004f1f2a278e20aa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 20 Jun 2008 21:25:48 +0000 Subject: [PATCH] Actions (so called sub-commands) may now have own pre/post filter, profile update is only to confirmed acctions available --- .gitattributes | 35 +++- .../ship-simu/class_ApplicationHelper.php | 4 +- application/ship-simu/config.php | 10 +- .../class_WebShipsimuGuestLoginCommand.php | 3 +- .../web/class_WebShipsimuProfileCommand.php | 5 +- .../web/class_WebShipsimuRegisterCommand.php | 3 +- .../web/class_WebShipsimuUserLoginCommand.php | 3 +- .../class_ShipSimuRegistration.php | 2 +- .../commands => exceptions/actions}/.htaccess | 0 .../actions/class_InvalidActionException.php | 46 +++++ .../class_InvalidControllerException.php | 46 +++++ ...class_AccountPasswordMismatchException.php | 45 +++++ .../actions/commands}/.htaccess | 0 .../commands/class_Commandable.php | 14 +- .../interfaces/resolver/actions/.htaccess | 1 + .../resolver/actions/class_ActionResolver.php | 51 +++++ .../interfaces/resolver/class_Resolver.php | 28 +++ .../interfaces/resolver/commands/.htaccess | 1 + .../commands/class_CommandResolver.php | 44 ++++ .../interfaces/resolver/controller/.htaccess | 1 + .../controller/class_ControllerResolver.php | 34 ++++ inc/classes/main/actions/web/.htaccess | 1 + .../web/class_WebLoginProfileAction.php | 83 ++++++++ .../main/class_BaseFrameworkSystem.php | 48 +++-- .../main/commands/class_BaseCommand.php | 24 --- .../commands/web/class_WebDoFormCommand.php | 3 +- .../commands/web/class_WebHomeCommand.php | 3 +- .../web/class_WebLoginAreaCommand.php | 67 ++++-- .../commands/web/class_WebLoginCommand.php | 3 +- .../web/class_WebLoginFailedCommand.php | 3 +- .../web/class_WebLogoutDoneCommand.php | 3 +- .../commands/web/class_WebRegisterCommand.php | 3 +- .../main/controller/class_BaseController.php | 27 +-- .../default/class_WebDefaultController.php | 2 +- .../class_WebDefaultNewsController.php | 4 +- .../default/class_WebLoginController.php | 4 +- .../class_WebLoginFailedController.php | 2 +- .../form/class_WebDoFormController.php | 2 +- .../login/class_WebLoginAreaController.php | 4 +- .../filter/change/class_EmailChangeFilter.php | 53 ++++- .../change/class_PasswordChangeFilter.php | 47 ++++- .../class_PasswordValidatorFilter.php | 6 +- .../class_AccountPasswordVerifierFilter.php | 106 ++++++++++ .../class_UserStatusVerifierFilter.php | 84 ++++++++ inc/classes/main/resolver/action/.htaccess | 1 + .../action/class_BaseActionResolver.php | 138 +++++++++++++ .../main/resolver/action/web/.htaccess | 1 + .../action/web/class_WebActionResolver.php | 153 ++++++++++++++ .../main/resolver/class_BaseResolver.php | 110 +--------- inc/classes/main/resolver/command/.htaccess | 1 + .../command/class_BaseCommandResolver.php | 139 +++++++++++++ .../class_WebCommandResolver.php | 0 .../main/resolver/command/web/.htaccess | 1 + .../command/web/class_WebCommandResolver.php | 190 ++++++++++++++++++ .../main/resolver/controller/.htaccess | 1 + .../class_BaseControllerResolver.php | 128 ++++++++++++ .../main/resolver/controller/web/.htaccess | 1 + .../web/class_WebControllerResolver.php | 75 ++++--- inc/config.php | 10 +- 59 files changed, 1633 insertions(+), 274 deletions(-) rename inc/classes/{interfaces/commands => exceptions/actions}/.htaccess (100%) create mode 100644 inc/classes/exceptions/actions/class_InvalidActionException.php create mode 100644 inc/classes/exceptions/controller/class_InvalidControllerException.php create mode 100644 inc/classes/exceptions/user/class_AccountPasswordMismatchException.php rename inc/classes/{main/resolver/web => interfaces/actions/commands}/.htaccess (100%) rename inc/classes/interfaces/{ => actions}/commands/class_Commandable.php (70%) create mode 100644 inc/classes/interfaces/resolver/actions/.htaccess create mode 100644 inc/classes/interfaces/resolver/actions/class_ActionResolver.php create mode 100644 inc/classes/interfaces/resolver/class_Resolver.php create mode 100644 inc/classes/interfaces/resolver/commands/.htaccess create mode 100644 inc/classes/interfaces/resolver/commands/class_CommandResolver.php create mode 100644 inc/classes/interfaces/resolver/controller/.htaccess create mode 100644 inc/classes/interfaces/resolver/controller/class_ControllerResolver.php create mode 100644 inc/classes/main/actions/web/.htaccess create mode 100644 inc/classes/main/actions/web/class_WebLoginProfileAction.php create mode 100644 inc/classes/main/filter/verifier/class_AccountPasswordVerifierFilter.php create mode 100644 inc/classes/main/filter/verifier/class_UserStatusVerifierFilter.php create mode 100644 inc/classes/main/resolver/action/.htaccess create mode 100644 inc/classes/main/resolver/action/class_BaseActionResolver.php create mode 100644 inc/classes/main/resolver/action/web/.htaccess create mode 100644 inc/classes/main/resolver/action/web/class_WebActionResolver.php create mode 100644 inc/classes/main/resolver/command/.htaccess create mode 100644 inc/classes/main/resolver/command/class_BaseCommandResolver.php rename inc/classes/main/resolver/{web => command}/class_WebCommandResolver.php (100%) create mode 100644 inc/classes/main/resolver/command/web/.htaccess create mode 100644 inc/classes/main/resolver/command/web/class_WebCommandResolver.php create mode 100644 inc/classes/main/resolver/controller/.htaccess create mode 100644 inc/classes/main/resolver/controller/class_BaseControllerResolver.php create mode 100644 inc/classes/main/resolver/controller/web/.htaccess rename inc/classes/main/resolver/{ => controller}/web/class_WebControllerResolver.php (67%) diff --git a/.gitattributes b/.gitattributes index 360ab57..fe0f6a6 100644 --- a/.gitattributes +++ b/.gitattributes @@ -165,6 +165,8 @@ inc/.htaccess -text inc/classes.php -text inc/classes/.htaccess -text inc/classes/exceptions/.htaccess -text +inc/classes/exceptions/actions/.htaccess -text +inc/classes/exceptions/actions/class_InvalidActionException.php -text inc/classes/exceptions/auth/.htaccess -text inc/classes/exceptions/auth/class_UserAuthorizationException.php -text inc/classes/exceptions/class_ -text @@ -177,6 +179,7 @@ inc/classes/exceptions/container/class_ContainerItemIsNullException.php -text inc/classes/exceptions/container/class_ContainerMaybeDamagedException.php -text inc/classes/exceptions/controller/.htaccess -text inc/classes/exceptions/controller/class_DefaultControllerException.php -text +inc/classes/exceptions/controller/class_InvalidControllerException.php -text inc/classes/exceptions/criteria/.htaccess -text inc/classes/exceptions/database/.htaccess -text inc/classes/exceptions/database/class_DatabaseException.php -text @@ -251,12 +254,15 @@ inc/classes/exceptions/template/class_UnexpectedTemplateTypeException.php -text inc/classes/exceptions/template/class_UnsupportedTemplateEngineException.php -text inc/classes/exceptions/template/class_ViewHelperNotFoundException.php -text inc/classes/exceptions/user/.htaccess -text +inc/classes/exceptions/user/class_AccountPasswordMismatchException.php -text inc/classes/exceptions/user/class_UserEmailMissingException.php -text inc/classes/exceptions/user/class_UserPasswordMismatchException.php -text inc/classes/exceptions/user/class_UsernameMissingException.php -text inc/classes/interfaces/.htaccess -text inc/classes/interfaces/actions/.htaccess -text inc/classes/interfaces/actions/class_PerformableAction.php -text +inc/classes/interfaces/actions/commands/.htaccess -text +inc/classes/interfaces/actions/commands/class_Commandable.php -text inc/classes/interfaces/application/.htaccess -text inc/classes/interfaces/application/class_ManageableApplication.php -text inc/classes/interfaces/auth/.htaccess -text @@ -265,8 +271,6 @@ inc/classes/interfaces/cache/.htaccess -text inc/classes/interfaces/cache/class_Cacheable.php -text inc/classes/interfaces/class_ -text inc/classes/interfaces/class_FrameworkInterface.php -text -inc/classes/interfaces/commands/.htaccess -text -inc/classes/interfaces/commands/class_Commandable.php -text inc/classes/interfaces/compressor/.htaccess -text inc/classes/interfaces/compressor/class_Compressor.php -text inc/classes/interfaces/controller/.htaccess -text @@ -310,8 +314,15 @@ inc/classes/interfaces/registry/class_Registerable.php -text inc/classes/interfaces/request/.htaccess -text inc/classes/interfaces/request/class_Requestable.php -text inc/classes/interfaces/resolver/.htaccess -text +inc/classes/interfaces/resolver/actions/.htaccess -text +inc/classes/interfaces/resolver/actions/class_ActionResolver.php -text inc/classes/interfaces/resolver/class_CommandResolver.php -text inc/classes/interfaces/resolver/class_ControllerResolver.php -text +inc/classes/interfaces/resolver/class_Resolver.php -text +inc/classes/interfaces/resolver/commands/.htaccess -text +inc/classes/interfaces/resolver/commands/class_CommandResolver.php -text +inc/classes/interfaces/resolver/controller/.htaccess -text +inc/classes/interfaces/resolver/controller/class_ControllerResolver.php -text inc/classes/interfaces/response/.htaccess -text inc/classes/interfaces/response/class_Responseable.php -text inc/classes/interfaces/result/.htaccess -text @@ -328,6 +339,8 @@ inc/classes/main/actions/class_ -text inc/classes/main/actions/class_BaseAction.php -text inc/classes/main/actions/post_registration/.htaccess -text inc/classes/main/actions/post_registration/class_LoginAfterRegistrationAction.php -text +inc/classes/main/actions/web/.htaccess -text +inc/classes/main/actions/web/class_WebLoginProfileAction.php -text inc/classes/main/auth/.htaccess -text inc/classes/main/auth/class_CookieAuth.php -text inc/classes/main/cache/.htaccess -text @@ -422,9 +435,11 @@ inc/classes/main/filter/validator/class_EmailValidatorFilter.php -text inc/classes/main/filter/validator/class_PasswordValidatorFilter.php -text inc/classes/main/filter/validator/class_UserNameValidatorFilter.php -text inc/classes/main/filter/verifier/.htaccess -text +inc/classes/main/filter/verifier/class_AccountPasswordVerifierFilter.php -text inc/classes/main/filter/verifier/class_EmailValidatorFilter.php -text inc/classes/main/filter/verifier/class_PasswordVerifierFilter.php -text inc/classes/main/filter/verifier/class_UserNameVerifierFilter.php -text +inc/classes/main/filter/verifier/class_UserStatusVerifierFilter.php -text inc/classes/main/helper/.htaccess -text inc/classes/main/helper/class_ -text inc/classes/main/helper/class_BaseHelper.php -text @@ -451,10 +466,20 @@ inc/classes/main/registry/class_Registry.php -text inc/classes/main/request/.htaccess -text inc/classes/main/request/class_HttpRequest.php -text inc/classes/main/resolver/.htaccess -text +inc/classes/main/resolver/action/.htaccess -text +inc/classes/main/resolver/action/class_BaseActionResolver.php -text +inc/classes/main/resolver/action/web/.htaccess -text +inc/classes/main/resolver/action/web/class_WebActionResolver.php -text inc/classes/main/resolver/class_BaseResolver.php -text -inc/classes/main/resolver/web/.htaccess -text -inc/classes/main/resolver/web/class_WebCommandResolver.php -text -inc/classes/main/resolver/web/class_WebControllerResolver.php -text +inc/classes/main/resolver/command/.htaccess -text +inc/classes/main/resolver/command/class_BaseCommandResolver.php -text +inc/classes/main/resolver/command/class_WebCommandResolver.php -text +inc/classes/main/resolver/command/web/.htaccess -text +inc/classes/main/resolver/command/web/class_WebCommandResolver.php -text +inc/classes/main/resolver/controller/.htaccess -text +inc/classes/main/resolver/controller/class_BaseControllerResolver.php -text +inc/classes/main/resolver/controller/web/.htaccess -text +inc/classes/main/resolver/controller/web/class_WebControllerResolver.php -text inc/classes/main/response/.htaccess -text inc/classes/main/response/class_HttpResponse.php -text inc/classes/main/result/.htaccess -text diff --git a/application/ship-simu/class_ApplicationHelper.php b/application/ship-simu/class_ApplicationHelper.php index ab372a5..32bd764 100644 --- a/application/ship-simu/class_ApplicationHelper.php +++ b/application/ship-simu/class_ApplicationHelper.php @@ -193,7 +193,7 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica $this->setResponseInstance($responseInstance); // Get the parameter from the request - $commandName = $requestInstance->getRequestElement("page"); + $commandName = $requestInstance->getRequestElement('page'); // If it is null then get default command if (is_null($commandName)) { @@ -204,7 +204,7 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica $resolverInstance = WebControllerResolver::createWebControllerResolver($commandName, $this); // Get a controller instance as well - $this->controllerInstance = $resolverInstance->resolveCommandController(); + $this->controllerInstance = $resolverInstance->resolveController(); // Handle the request $this->controllerInstance->handleRequest($requestInstance, $responseInstance); diff --git a/application/ship-simu/config.php b/application/ship-simu/config.php index cef723c..6210fb0 100644 --- a/application/ship-simu/config.php +++ b/application/ship-simu/config.php @@ -77,11 +77,14 @@ $cfg->setConfigEntry('user_login_class', "ShipSimuUserLogin"); $cfg->setConfigEntry('guest_login_class', "ShipSimuGuestLogin"); // CFG: USER-STATUS-REGISTER -$cfg->setConfigEntry('user_status_register', "UNCONFIRMED"); +$cfg->setConfigEntry('user_status_unconfirmed', "UNCONFIRMED"); -// CFG: GUEST-STATUS +// CFG: USER-STATUS-GUEST $cfg->setConfigEntry('user_status_guest', "GUEST"); +// CFG: USER-STATUS-CONFIRMED +$cfg->setConfigEntry('user_status_confirmed', "CONFIRMED"); + // CFG: LOGIN-HELPER $cfg->setConfigEntry('login_helper_class', "ShipSimuLoginHelper"); @@ -97,6 +100,9 @@ $cfg->setConfigEntry('login_failed_url', "index.php?app=ship-simu&page=login_fai // CFG: LOGOUT-DONE-URL $cfg->setConfigEntry('logout_done_url', "index.php?app=ship-simu&page=logout_done"); +// CFG: LOGIN-USER-STATUS-URL +$cfg->setConfigEntry('login_user_status_url', "index.php?app=ship-simu&page=login_status_problem"); + // CFG: LOGIN-DEFAULT-ACTION $cfg->setConfigEntry('login_default_action', "welcome"); diff --git a/application/ship-simu/main/commands/web/class_WebShipsimuGuestLoginCommand.php b/application/ship-simu/main/commands/web/class_WebShipsimuGuestLoginCommand.php index 2fd8165..0ed651a 100644 --- a/application/ship-simu/main/commands/web/class_WebShipsimuGuestLoginCommand.php +++ b/application/ship-simu/main/commands/web/class_WebShipsimuGuestLoginCommand.php @@ -98,9 +98,10 @@ class WebShipsimuGuestLoginCommand extends BaseCommand implements Commandable { * Adds extra filters to the given controller instance * * @param $controllerInstance A controller instance + * @param $requestInstance An instance of a class with an Requestable interface * @return void */ - function addExtraFilters (Controller $controllerInstance) { + public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { // Which login type do we have? switch ($this->getConfigInstance()->readConfig('login_type')) { case "username": // Login via username diff --git a/application/ship-simu/main/commands/web/class_WebShipsimuProfileCommand.php b/application/ship-simu/main/commands/web/class_WebShipsimuProfileCommand.php index fe1f6c2..320c1d5 100644 --- a/application/ship-simu/main/commands/web/class_WebShipsimuProfileCommand.php +++ b/application/ship-simu/main/commands/web/class_WebShipsimuProfileCommand.php @@ -120,14 +120,17 @@ class WebShipsimuProfileCommand extends BaseCommand implements Commandable { * Adds extra filters to the given controller instance * * @param $controllerInstance A controller instance + * @param $requestInstance An instance of a class with an Requestable interface * @return void */ - function addExtraFilters (Controller $controllerInstance) { + public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { // Add user auth filter (we don't need an update of the user here because it will be redirected) $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_auth_class')); /* @TODO Add some more pre/post filters to the controller */ + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_status_class')); $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('rules_accepted_class')); + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('account_password_class')); $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('email_change_class')); $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('password_change_class')); } diff --git a/application/ship-simu/main/commands/web/class_WebShipsimuRegisterCommand.php b/application/ship-simu/main/commands/web/class_WebShipsimuRegisterCommand.php index 61c537a..b8c7b61 100644 --- a/application/ship-simu/main/commands/web/class_WebShipsimuRegisterCommand.php +++ b/application/ship-simu/main/commands/web/class_WebShipsimuRegisterCommand.php @@ -95,9 +95,10 @@ class WebShipsimuRegisterCommand extends BaseCommand implements Commandable { * Adds extra filters to the given controller instance * * @param $controllerInstance A controller instance + * @param $requestInstance An instance of a class with an Requestable interface * @return void */ - function addExtraFilters (Controller $controllerInstance) { + public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { /* @TODO Add some more pre/post filters to the controller */ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('email_validator_class')); $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('username_validator_class')); diff --git a/application/ship-simu/main/commands/web/class_WebShipsimuUserLoginCommand.php b/application/ship-simu/main/commands/web/class_WebShipsimuUserLoginCommand.php index 2eff732..a9d252e 100644 --- a/application/ship-simu/main/commands/web/class_WebShipsimuUserLoginCommand.php +++ b/application/ship-simu/main/commands/web/class_WebShipsimuUserLoginCommand.php @@ -98,9 +98,10 @@ class WebShipsimuUserLoginCommand extends BaseCommand implements Commandable { * Adds extra filters to the given controller instance * * @param $controllerInstance A controller instance + * @param $requestInstance An instance of a class with an Requestable interface * @return void */ - function addExtraFilters (Controller $controllerInstance) { + public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { // Which login type do we have? switch ($this->getConfigInstance()->readConfig('login_type')) { case "username": // Login via username diff --git a/application/ship-simu/main/registration/class_ShipSimuRegistration.php b/application/ship-simu/main/registration/class_ShipSimuRegistration.php index eac7106..9dc9fb3 100644 --- a/application/ship-simu/main/registration/class_ShipSimuRegistration.php +++ b/application/ship-simu/main/registration/class_ShipSimuRegistration.php @@ -157,7 +157,7 @@ class ShipSimuRegistration extends BaseRegistration { */ public function addElementsToDataSet (StoreableCriteria $criteriaInstance) { // Default is user account! - $configEntry = 'user_status_register'; + $configEntry = 'user_status_unconfirmed'; // Add a lot elements to the dataset criteria foreach ($this->criteriaElements as $alias=>$element) { diff --git a/inc/classes/interfaces/commands/.htaccess b/inc/classes/exceptions/actions/.htaccess similarity index 100% rename from inc/classes/interfaces/commands/.htaccess rename to inc/classes/exceptions/actions/.htaccess diff --git a/inc/classes/exceptions/actions/class_InvalidActionException.php b/inc/classes/exceptions/actions/class_InvalidActionException.php new file mode 100644 index 0000000..4aa1b96 --- /dev/null +++ b/inc/classes/exceptions/actions/class_InvalidActionException.php @@ -0,0 +1,46 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class InvalidActionException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $msgArray An array with message parts + * @param $code An optional code for better debugging + * @return void + */ + public function __construct(array $msgArray, $code) { + // Prepare the message + $message = sprintf("[%s:%d] Cannot resolve action %s.", + $msgArray[0]->__toString(), + $this->getLine(), + $msgArray[1] + ); + + // Call parent contructor with message + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/controller/class_InvalidControllerException.php b/inc/classes/exceptions/controller/class_InvalidControllerException.php new file mode 100644 index 0000000..f221696 --- /dev/null +++ b/inc/classes/exceptions/controller/class_InvalidControllerException.php @@ -0,0 +1,46 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class InvalidControllerException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $msgArray An array with message parts + * @param $code An optional code for better debugging + * @return void + */ + public function __construct(array $msgArray, $code) { + // Prepare the message + $message = sprintf("[%s:%d] Cannot resolve controller %s.", + $msgArray[0]->__toString(), + $this->getLine(), + $msgArray[1] + ); + + // Call parent contructor with message + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/user/class_AccountPasswordMismatchException.php b/inc/classes/exceptions/user/class_AccountPasswordMismatchException.php new file mode 100644 index 0000000..10b873b --- /dev/null +++ b/inc/classes/exceptions/user/class_AccountPasswordMismatchException.php @@ -0,0 +1,45 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class AccountPasswordMismatchException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $filterInstance A filterable class instance + * @param $code An optional code for better debugging + * @return void + */ + public function __construct(Filterable $filterInstance, $code) { + // Create the message + $message = sprintf("[%s:%d] Supplied account password did not match with stored.", + $filterInstance->__toString(), + $this->getLine() + ); + + // Make sure everything is assigned properly + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/resolver/web/.htaccess b/inc/classes/interfaces/actions/commands/.htaccess similarity index 100% rename from inc/classes/main/resolver/web/.htaccess rename to inc/classes/interfaces/actions/commands/.htaccess diff --git a/inc/classes/interfaces/commands/class_Commandable.php b/inc/classes/interfaces/actions/commands/class_Commandable.php similarity index 70% rename from inc/classes/interfaces/commands/class_Commandable.php rename to inc/classes/interfaces/actions/commands/class_Commandable.php index fa87963..7b5beea 100644 --- a/inc/classes/interfaces/commands/class_Commandable.php +++ b/inc/classes/interfaces/actions/commands/class_Commandable.php @@ -21,23 +21,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -interface Commandable extends FrameworkInterface { - /** - * Executes the command with given request and response objects - * - * @param $requestInstance An instance of a class with an Requestable interface - * @param $responseInstance An instance of a class with an Responseable interface - * @return void - */ - function execute (Requestable $requestInstance, Responseable $responseInstance); - +interface Commandable extends PerformableAction { /** * Adds extra filters to the given controller instance * * @param $controllerInstance A controller instance + * @param $requestInstance An instance of a class with an Requestable interface * @return void */ - function addExtraFilters (Controller $controllerInstance); + function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance); } // diff --git a/inc/classes/interfaces/resolver/actions/.htaccess b/inc/classes/interfaces/resolver/actions/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/interfaces/resolver/actions/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/interfaces/resolver/actions/class_ActionResolver.php b/inc/classes/interfaces/resolver/actions/class_ActionResolver.php new file mode 100644 index 0000000..289d508 --- /dev/null +++ b/inc/classes/interfaces/resolver/actions/class_ActionResolver.php @@ -0,0 +1,51 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +interface ActionResolver extends Resolver { + /** + * Returns an action instance for the current action + * + * @return $actionInstance An instance of the resolved action + */ + function resolveAction (); + + /** + * Returns an action instance for a given request class + * + * @param $requestInstance An instance of a request class + * @return $actionInstance An instance of the resolved action + */ + function resolveActionByRequest (Requestable $requestInstance); + + /** + * Checks wether the given action is valid + * + * @param $actionName The default action we shall execute + * @return $isValid Wether the given action is valid + * @throws EmptyVariableException Thrown if the given action is not set + */ + function isActionValid ($actionName); +} + +// +?> diff --git a/inc/classes/interfaces/resolver/class_Resolver.php b/inc/classes/interfaces/resolver/class_Resolver.php new file mode 100644 index 0000000..8d4a533 --- /dev/null +++ b/inc/classes/interfaces/resolver/class_Resolver.php @@ -0,0 +1,28 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +interface Resolver extends FrameworkInterface { +} + +// +?> diff --git a/inc/classes/interfaces/resolver/commands/.htaccess b/inc/classes/interfaces/resolver/commands/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/interfaces/resolver/commands/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/interfaces/resolver/commands/class_CommandResolver.php b/inc/classes/interfaces/resolver/commands/class_CommandResolver.php new file mode 100644 index 0000000..bab8903 --- /dev/null +++ b/inc/classes/interfaces/resolver/commands/class_CommandResolver.php @@ -0,0 +1,44 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +interface CommandResolver extends Resolver { + /** + * Returns an command instance for a given request class + * + * @param $requestInstance An instance of a request class + * @return $commandInstance An instance of the resolved command + */ + function resolveCommandByRequest (Requestable $requestInstance); + + /** + * Checks wether the given command is valid + * + * @param $commandName The default command we shall execute + * @return $isValid Wether the given command is valid + * @throws EmptyVariableException Thrown if the given command is not set + */ + function isCommandValid ($commandName); +} + +// +?> diff --git a/inc/classes/interfaces/resolver/controller/.htaccess b/inc/classes/interfaces/resolver/controller/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/interfaces/resolver/controller/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/interfaces/resolver/controller/class_ControllerResolver.php b/inc/classes/interfaces/resolver/controller/class_ControllerResolver.php new file mode 100644 index 0000000..be95234 --- /dev/null +++ b/inc/classes/interfaces/resolver/controller/class_ControllerResolver.php @@ -0,0 +1,34 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +interface ControllerResolver extends Resolver { + /** + * Resolves the default controller of the given command + * + * @return $controllerInstance A controller instance for the default command + */ + function resolveController (); +} + +// +?> diff --git a/inc/classes/main/actions/web/.htaccess b/inc/classes/main/actions/web/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/actions/web/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/actions/web/class_WebLoginProfileAction.php b/inc/classes/main/actions/web/class_WebLoginProfileAction.php new file mode 100644 index 0000000..8a8532f --- /dev/null +++ b/inc/classes/main/actions/web/class_WebLoginProfileAction.php @@ -0,0 +1,83 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class WebLoginProfileAction extends BaseAction implements Commandable, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set description + $this->setObjectDescription("Web profile action"); + + // Generate unique key + $this->generateUniqueId(); + } + + /** + * Creates an instance of this action + * + * @param $resolverInstance An instance of an action resolver + * @return $actionInstance An instance of this action class + */ + public final static function createWebLoginProfileAction (ActionResolver $resolverInstance) { + // Get a new instance + $actionInstance = new WebLoginProfileAction(); + + // Set the resolver instance + $actionInstance->setResolverInstance($resolverInstance); + + // Return the instance + return $actionInstance; + } + + /** + * Executes the command with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Dummy method + } + + /** + * Adds extra filters to the given controller instance + * + * @param $controllerInstance A controller instance + * @param $requestInstance An instance of a class with an Requestable interface + * @return void + */ + public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { + // Add user status filter here + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_status_class')); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index b725a85..a828dc7 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -48,6 +48,16 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ private $searchInstance = null; + /** + * The file I/O instance for the template loader + */ + private $fileIoInstance = null; + + /** + * Resolver instance + */ + private $resolverInstance = null; + /** * The real class name */ @@ -73,11 +83,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ private $decimals = ","; // German - /** - * The file I/O instance for the template loader - */ - private $fileIoInstance = null; - /*********************** * Exception codes.... * ***********************/ @@ -130,14 +135,12 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { const EXCEPTION_MISSING_LANGUAGE_HANDLER = 0x02e; const EXCEPTION_MISSING_FILE_IO_HANDLER = 0x02f; const EXCEPTION_MISSING_ELEMENT = 0x030; - const EXCEPTION_INVALID_COMMAND = 0x031; - const EXCEPTION_INVALID_CONTROLLER = 0x032; - const EXCEPTION_HEADERS_ALREADY_SENT = 0x033; - const EXCEPTION_DEFAUL_CONTROLLER_GONE = 0x034; - const EXCEPTION_CLASS_NOT_FOUND = 0x035; - const EXCEPTION_REQUIRED_INTERFACE_MISSING = 0x036; - const EXCEPTION_FATAL_ERROR = 0x037; - const EXCEPTION_FILE_NOT_FOUND = 0x038; + const EXCEPTION_HEADERS_ALREADY_SENT = 0x031; + const EXCEPTION_DEFAUL_CONTROLLER_GONE = 0x032; + const EXCEPTION_CLASS_NOT_FOUND = 0x033; + const EXCEPTION_REQUIRED_INTERFACE_MISSING = 0x034; + const EXCEPTION_FATAL_ERROR = 0x035; + const EXCEPTION_FILE_NOT_FOUND = 0x036; /** * In the super constructor these system classes shall be ignored or else @@ -992,6 +995,25 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { public final function getSearchInstance () { return $this->searchInstance; } + + /** + * Setter for resolver instance + * + * @param $resolverInstance Instance of a command resolver class + * @return void + */ + public final function setResolverInstance (Resolver $resolverInstance) { + $this->resolverInstance = $resolverInstance; + } + + /** + * Getter for resolver instance + * + * @return $resolverInstance Instance of a command resolver class + */ + public final function getResolverInstance () { + return $this->resolverInstance; + } } // [EOF] diff --git a/inc/classes/main/commands/class_BaseCommand.php b/inc/classes/main/commands/class_BaseCommand.php index 825b2b0..505d8ad 100644 --- a/inc/classes/main/commands/class_BaseCommand.php +++ b/inc/classes/main/commands/class_BaseCommand.php @@ -27,11 +27,6 @@ class BaseCommand extends BaseFrameworkSystem { */ private $controllerName = ""; - /** - * Resolver instance - */ - private $resolverInstance = null; - /** * Protected constructor * @@ -60,25 +55,6 @@ class BaseCommand extends BaseFrameworkSystem { public final function getControllerName () { return $this->controllerName; } - - /** - * Setter for resolver instance - * - * @param $resolverInstance Instance of a command resolver class - * @return void - */ - public final function setResolverInstance (CommandResolver $resolverInstance) { - $this->resolverInstance = $resolverInstance; - } - - /** - * Getter for resolver instance - * - * @return $resolverInstance Instance of a command resolver class - */ - public final function getResolverInstance () { - return $this->resolverInstance; - } } // [EOF] diff --git a/inc/classes/main/commands/web/class_WebDoFormCommand.php b/inc/classes/main/commands/web/class_WebDoFormCommand.php index dfd7b2c..3dde736 100644 --- a/inc/classes/main/commands/web/class_WebDoFormCommand.php +++ b/inc/classes/main/commands/web/class_WebDoFormCommand.php @@ -74,9 +74,10 @@ class WebDoFormCommand extends BaseCommand implements Commandable { * Adds extra filters to the given controller instance * * @param $controllerInstance A controller instance + * @param $requestInstance An instance of a class with an Requestable interface * @return void */ - function addExtraFilters (Controller $controllerInstance) { + public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { // Empty for now } diff --git a/inc/classes/main/commands/web/class_WebHomeCommand.php b/inc/classes/main/commands/web/class_WebHomeCommand.php index 704ee5f..d04e77a 100644 --- a/inc/classes/main/commands/web/class_WebHomeCommand.php +++ b/inc/classes/main/commands/web/class_WebHomeCommand.php @@ -114,9 +114,10 @@ class WebHomeCommand extends BaseCommand implements Commandable { * Adds extra filters to the given controller instance * * @param $controllerInstance A controller instance + * @param $requestInstance An instance of a class with an Requestable interface * @return void */ - function addExtraFilters (Controller $controllerInstance) { + public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { // Empty for now } } diff --git a/inc/classes/main/commands/web/class_WebLoginAreaCommand.php b/inc/classes/main/commands/web/class_WebLoginAreaCommand.php index 146623d..1143d22 100644 --- a/inc/classes/main/commands/web/class_WebLoginAreaCommand.php +++ b/inc/classes/main/commands/web/class_WebLoginAreaCommand.php @@ -22,6 +22,11 @@ * along with this program. If not, see . */ class WebLoginAreaCommand extends BaseCommand implements Commandable { + /** + * Name of the action + */ + private $actionName = ""; + /** * Protected constructor * @@ -78,22 +83,8 @@ class WebLoginAreaCommand extends BaseCommand implements Commandable { * @return void */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { - // Default action is the one from configuration - $actionClass = sprintf("login_%s_action_class", $this->getConfigInstance()->readConfig('login_default_action')); - $action = sprintf("login_%s", $this->getConfigInstance()->readConfig('login_default_action')); - - // Get "action" from request - $actReq = $requestInstance->getRequestElement('action'); - - // Do we have a "action" parameter set? - if (is_string($actReq)) { - // Then use it with prefix - $actionClass = sprintf("login_%s_action_class", $actReq); - $action = sprintf("login_%s", $actReq); - } // END - if - - // Get an action instance - $actionInstance = ObjectFactory::createObjectByConfiguredName($actionClass); + // Get the action instance from registry + $actionInstance = Registry::getRegistry()->getInstance('action'); // Execute the action (shall not output anything, see below why) $actionInstance->execute($requestInstance, $responseInstance); @@ -128,11 +119,11 @@ class WebLoginAreaCommand extends BaseCommand implements Commandable { $templateInstance->assignTemplateWithVariable("footer", "footer"); // Load the matching template - $templateInstance->loadCodeTemplate($action); + $templateInstance->loadCodeTemplate($this->actionName); // Assign the template with the master template as a content ... ;) $templateInstance->compileTemplate(); - $templateInstance->assignTemplateWithVariable($action, "login_content"); + $templateInstance->assignTemplateWithVariable($this->actionName, "login_content"); // Load main template $templateInstance->loadCodeTemplate("login_main"); @@ -145,7 +136,7 @@ class WebLoginAreaCommand extends BaseCommand implements Commandable { $templateInstance->loadCodeTemplate($masterTemplate); // Set title - $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage($action."_title")); + $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage($this->actionName."_title")); // ... and all variables. This should be merged together in a pattern // to make things easier. A cache mechanism should be added between @@ -161,10 +152,44 @@ class WebLoginAreaCommand extends BaseCommand implements Commandable { * Adds extra filters to the given controller instance * * @param $controllerInstance A controller instance + * @param $requestInstance An instance of a class with an Requestable interface * @return void */ - function addExtraFilters (Controller $controllerInstance) { - // Empty for now + public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { + // Default is no action + $actionInstance = null; + + // Default action is the one from configuration + $this->actionName = sprintf("login_%s", $this->getConfigInstance()->readConfig('login_default_action')); + + // Get "action" from request + $actReq = $requestInstance->getRequestElement('action'); + + // Do we have a "action" parameter set? + if ((is_string($actReq)) && (!empty($actReq))) { + // Then use it with prefix + $this->actionName = sprintf("login_%s", $actReq); + } // END - if + + // Get application instance + $applicationInstance = $this->getResolverInstance()->getApplicationInstance(); + + // Try to get an action resolver for the given action + try { + // Get a resolver + $actionResolver = WebActionResolver::createWebActionResolver($this->actionName, $applicationInstance); + + // Resolve the action + $actionInstance = $actionResolver->resolveAction(); + + // Add more action-specific filters + $actionInstance->addExtraFilters($controllerInstance, $requestInstance); + + // Remember this action in registry + Registry::getRegistry()->addInstance('action', $actionInstance); + } catch (InvalidActionException $e) { + // Silently ignored because no special action was found + } } } diff --git a/inc/classes/main/commands/web/class_WebLoginCommand.php b/inc/classes/main/commands/web/class_WebLoginCommand.php index b5a89ac..6fadf04 100644 --- a/inc/classes/main/commands/web/class_WebLoginCommand.php +++ b/inc/classes/main/commands/web/class_WebLoginCommand.php @@ -117,9 +117,10 @@ class WebLoginCommand extends BaseCommand implements Commandable { * Adds extra filters to the given controller instance * * @param $controllerInstance A controller instance + * @param $requestInstance An instance of a class with an Requestable interface * @return void */ - function addExtraFilters (Controller $controllerInstance) { + public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { // Empty for now } } diff --git a/inc/classes/main/commands/web/class_WebLoginFailedCommand.php b/inc/classes/main/commands/web/class_WebLoginFailedCommand.php index c7baa75..eead89a 100644 --- a/inc/classes/main/commands/web/class_WebLoginFailedCommand.php +++ b/inc/classes/main/commands/web/class_WebLoginFailedCommand.php @@ -117,9 +117,10 @@ class WebLoginFailedCommand extends BaseCommand implements Commandable { * Adds extra filters to the given controller instance * * @param $controllerInstance A controller instance + * @param $requestInstance An instance of a class with an Requestable interface * @return void */ - function addExtraFilters (Controller $controllerInstance) { + public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { // Empty for now } } diff --git a/inc/classes/main/commands/web/class_WebLogoutDoneCommand.php b/inc/classes/main/commands/web/class_WebLogoutDoneCommand.php index 5c38d06..3759b5e 100644 --- a/inc/classes/main/commands/web/class_WebLogoutDoneCommand.php +++ b/inc/classes/main/commands/web/class_WebLogoutDoneCommand.php @@ -117,9 +117,10 @@ class WebLogoutDoneCommand extends BaseCommand implements Commandable { * Adds extra filters to the given controller instance * * @param $controllerInstance A controller instance + * @param $requestInstance An instance of a class with an Requestable interface * @return void */ - function addExtraFilters (Controller $controllerInstance) { + public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { // Empty for now } } diff --git a/inc/classes/main/commands/web/class_WebRegisterCommand.php b/inc/classes/main/commands/web/class_WebRegisterCommand.php index 2a50f5e..f4cc325 100644 --- a/inc/classes/main/commands/web/class_WebRegisterCommand.php +++ b/inc/classes/main/commands/web/class_WebRegisterCommand.php @@ -118,9 +118,10 @@ class WebRegisterCommand extends BaseCommand implements Commandable { * Adds extra filters to the given controller instance * * @param $controllerInstance A controller instance + * @param $requestInstance An instance of a class with an Requestable interface * @return void */ - function addExtraFilters (Controller $controllerInstance) { + public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { // Empty for now } } diff --git a/inc/classes/main/controller/class_BaseController.php b/inc/classes/main/controller/class_BaseController.php index 4438cc2..b2951f5 100644 --- a/inc/classes/main/controller/class_BaseController.php +++ b/inc/classes/main/controller/class_BaseController.php @@ -23,12 +23,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class BaseController extends BaseFrameworkSystem { - /** - * Instance of a CommandResolver class - */ - private $resolverInstance = null; - +class BaseController extends BaseFrameworkSystem implements Registerable { /** * Pre filter chain instance */ @@ -55,25 +50,9 @@ class BaseController extends BaseFrameworkSystem { // Initialize both filter chains $this->preFilterChain = ObjectFactory::createObjectByConfiguredName('filter_chain_class'); $this->postFilterChain = ObjectFactory::createObjectByConfiguredName('filter_chain_class'); - } - /** - * Getter for a command resolver instance - * - * @return $resolverInstance An instance of a command resolver class - */ - public final function getResolverInstance () { - return $this->resolverInstance; - } - - /** - * Setter for a command resolver instance - * - * @param $resolverInstance An instance of a command resolver class - * @return void - */ - public final function setResolverInstance (CommandResolver $resolverInstance) { - $this->resolverInstance = $resolverInstance; + // Add this controller to the registry + Registry::getRegistry()->addInstance('controller', $this); } /** diff --git a/inc/classes/main/controller/default/class_WebDefaultController.php b/inc/classes/main/controller/default/class_WebDefaultController.php index 59c51c3..7f7e862 100644 --- a/inc/classes/main/controller/default/class_WebDefaultController.php +++ b/inc/classes/main/controller/default/class_WebDefaultController.php @@ -65,7 +65,7 @@ class WebDefaultController extends BaseController implements Controller { */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { // Get the command instance - $commandInstance = $this->getResolverInstance()->resolvCommandByRequest($requestInstance); + $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); // This request was valid! :-D $requestInstance->requestIsValid(); diff --git a/inc/classes/main/controller/default/class_WebDefaultNewsController.php b/inc/classes/main/controller/default/class_WebDefaultNewsController.php index e0f506a..03f29d2 100644 --- a/inc/classes/main/controller/default/class_WebDefaultNewsController.php +++ b/inc/classes/main/controller/default/class_WebDefaultNewsController.php @@ -68,10 +68,10 @@ class WebDefaultNewsController extends BaseController implements Controller { */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { // Get the command instance from the resolver by sending a request instance to the resolver - $commandInstance = $this->getResolverInstance()->resolvCommandByRequest($requestInstance); + $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); // Add more filters by the command - $commandInstance->addExtraFilters($this); + $commandInstance->addExtraFilters($this, $requestInstance); // Run the pre filters $this->executePreFilters($requestInstance, $responseInstance); diff --git a/inc/classes/main/controller/default/class_WebLoginController.php b/inc/classes/main/controller/default/class_WebLoginController.php index 5bc762c..0ec8c3b 100644 --- a/inc/classes/main/controller/default/class_WebLoginController.php +++ b/inc/classes/main/controller/default/class_WebLoginController.php @@ -67,10 +67,10 @@ class WebLoginController extends BaseController implements Controller { */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { // Get the command instance from the resolver by sending a request instance to the resolver - $commandInstance = $this->getResolverInstance()->resolvCommandByRequest($requestInstance); + $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); // Add more filters by the command - $commandInstance->addExtraFilters($this); + $commandInstance->addExtraFilters($this, $requestInstance); // Run the pre filters $this->executePreFilters($requestInstance, $responseInstance); diff --git a/inc/classes/main/controller/default/class_WebLoginFailedController.php b/inc/classes/main/controller/default/class_WebLoginFailedController.php index f3a7ce4..3cd5d60 100644 --- a/inc/classes/main/controller/default/class_WebLoginFailedController.php +++ b/inc/classes/main/controller/default/class_WebLoginFailedController.php @@ -64,7 +64,7 @@ class WebLoginFailedController extends BaseController implements Controller { */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { // Get the command instance - $commandInstance = $this->getResolverInstance()->resolvCommandByRequest($requestInstance); + $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); // This request was valid! :-D $requestInstance->requestIsValid(); diff --git a/inc/classes/main/controller/form/class_WebDoFormController.php b/inc/classes/main/controller/form/class_WebDoFormController.php index 42171a6..4d6a0b1 100644 --- a/inc/classes/main/controller/form/class_WebDoFormController.php +++ b/inc/classes/main/controller/form/class_WebDoFormController.php @@ -73,7 +73,7 @@ class WebDoFormController extends BaseController implements Controller { $commandInstance = $this->getResolverInstance()->resolveCommand($formAction); // Add more filters by the command - $commandInstance->addExtraFilters($this); + $commandInstance->addExtraFilters($this, $requestInstance); // Try to run the pre filters, if auth exceptions come through redirect here try { diff --git a/inc/classes/main/controller/login/class_WebLoginAreaController.php b/inc/classes/main/controller/login/class_WebLoginAreaController.php index 4bc6f29..e14a0ee 100644 --- a/inc/classes/main/controller/login/class_WebLoginAreaController.php +++ b/inc/classes/main/controller/login/class_WebLoginAreaController.php @@ -78,10 +78,10 @@ class WebLoginAreaController extends BaseController implements Controller { */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { // Get the command instance from the resolver by sending a request instance to the resolver - $commandInstance = $this->getResolverInstance()->resolvCommandByRequest($requestInstance); + $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); // Add more filters by the command - $commandInstance->addExtraFilters($this); + $commandInstance->addExtraFilters($this, $requestInstance); // Try to run the pre filters, if auth exceptions come through redirect here try { diff --git a/inc/classes/main/filter/change/class_EmailChangeFilter.php b/inc/classes/main/filter/change/class_EmailChangeFilter.php index 8005cc9..7e1dd57 100644 --- a/inc/classes/main/filter/change/class_EmailChangeFilter.php +++ b/inc/classes/main/filter/change/class_EmailChangeFilter.php @@ -63,8 +63,57 @@ class EmailChangeFilter extends BaseFrameworkSystem implements Filterable { * @return void */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { - // Implement this! - $this->partialStub("Please implement this method."); + // Get both emails + $email1 = $requestInstance->getRequestElement('email1'); + $email2 = $requestInstance->getRequestElement('email2'); + + // Is only first email set? + if ((!empty($email1)) && (empty($email2))) { + // Request is invalid! + $requestInstance->requestIsValid(false); + + // Email 2 is empty + $responseInstance->addFatalMessage('email2_empty'); + + // Stop processing here + return false; + } // END - if + + // Is only second email set? + if ((empty($email1)) && (!empty($email2))) { + // Request is invalid! + $requestInstance->requestIsValid(false); + + // Email 1 is empty + $responseInstance->addFatalMessage('email1_empty'); + + // Stop processing here + return false; + } // END - if + + // Do both match? + if ($email1 != $email2) { + // Request is invalid! + $requestInstance->requestIsValid(false); + + // Emails are mismatching + $responseInstance->addFatalMessage('emails_mismatch'); + + // Stop processing here + return false; + } // END - if + + // Now, get a user instance for comparison + $userInstance = Registry::getRegistry()->getInstance('user'); + + // Get the email field + $userEmail = $userInstance->getField('email'); + + // Are they different? + if ($email != $email1) { + // Update the "new_email" field + $this->partialStub("Unfinished part."); + } // END - if } } diff --git a/inc/classes/main/filter/change/class_PasswordChangeFilter.php b/inc/classes/main/filter/change/class_PasswordChangeFilter.php index 353ad72..9c306bf 100644 --- a/inc/classes/main/filter/change/class_PasswordChangeFilter.php +++ b/inc/classes/main/filter/change/class_PasswordChangeFilter.php @@ -63,8 +63,51 @@ class PasswordChangeFilter extends BaseFrameworkSystem implements Filterable { * @return void */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { - // Implement this! - $this->partialStub("Please implement this method."); + // Get both passwords + $pass1 = $requestInstance->getRequestElement('pass1'); + $pass2 = $requestInstance->getRequestElement('pass2'); + + // Is only first email set? + if ((!empty($pass1)) && (empty($pass2))) { + // Request is invalid! + $requestInstance->requestIsValid(false); + + // Email 2 is empty + $responseInstance->addFatalMessage('pass2_empty'); + + // Stop processing here + return false; + } // END - if + + // Is only second pass set? + if ((empty($pass1)) && (!empty($pass2))) { + // Request is invalid! + $requestInstance->requestIsValid(false); + + // Email 1 is empty + $responseInstance->addFatalMessage('pass1_empty'); + + // Stop processing here + return false; + } // END - if + + // Do both match? + if ($pass1 != $pass2) { + // Request is invalid! + $requestInstance->requestIsValid(false); + + // Emails are mismatching + $responseInstance->addFatalMessage('pass_mismatch'); + + // Stop processing here + return false; + } // END - if + + // Now, get a user instance for comparison + $userInstance = Registry::getRegistry()->getInstance('user'); + + // Update the "password" field + $this->partialStub("Unfinished part."); } } diff --git a/inc/classes/main/filter/validator/class_PasswordValidatorFilter.php b/inc/classes/main/filter/validator/class_PasswordValidatorFilter.php index 1d371b1..b7092f9 100644 --- a/inc/classes/main/filter/validator/class_PasswordValidatorFilter.php +++ b/inc/classes/main/filter/validator/class_PasswordValidatorFilter.php @@ -81,13 +81,13 @@ class PasswordValidatorFilter extends BaseFilter implements Filterable { // Is the password empty? if (empty($password1)) { // Add a message to the response - $responseInstance->addFatalMessage('password1_empty'); + $responseInstance->addFatalMessage('pass1_empty'); } // END - if // Is the confirmation empty? if (empty($password2)) { // Add a message to the response - $responseInstance->addFatalMessage('password2_empty'); + $responseInstance->addFatalMessage('pass2_empty'); } // END - if // Abort here @@ -97,7 +97,7 @@ class PasswordValidatorFilter extends BaseFilter implements Filterable { $requestInstance->requestIsValid(false); // Add a message to the response - $responseInstance->addFatalMessage('passwords_mismatching'); + $responseInstance->addFatalMessage('pass_mismatch'); // Abort here return false; diff --git a/inc/classes/main/filter/verifier/class_AccountPasswordVerifierFilter.php b/inc/classes/main/filter/verifier/class_AccountPasswordVerifierFilter.php new file mode 100644 index 0000000..1525973 --- /dev/null +++ b/inc/classes/main/filter/verifier/class_AccountPasswordVerifierFilter.php @@ -0,0 +1,106 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class AccountPasswordVerifierFilter extends BaseFilter implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("A filter for account password verification"); + + // Create unique ID number + $this->generateUniqueId(); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function createAccountPasswordVerifierFilter () { + // Get a new instance + $filterInstance = new AccountPasswordVerifierFilter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @throws AccountPasswordMismatchException If the account password does not match + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get password + $password = $requestInstance->getRequestElement('pass_old'); + + // Is the password still not set? + if (is_null($password)) { + // Not found in form so stop the filtering process + $requestInstance->requestIsValid(false); + + // Add a message to the response + $responseInstance->addFatalMessage('pass_old_unset'); + + // Abort here + return false; + } elseif (empty($password)) { + // Password is empty + $requestInstance->requestIsValid(false); + + // Add a message to the response + $responseInstance->addFatalMessage('pass_old_empty'); + + // Abort here + return false; + } + + // Get a user instance + $userInstance = Registry::getRegistry()->getInstance('user'); + + // Get old hash + $oldHash = $userInstance->getField('pass_hash'); + + // Get an encryption helper and encrypt the password + $passHash = ObjectFactory::createObjectByConfiguredName('crypto_class')->hashPassword($password, $oldHash); + + // Does it match? + if ($oldHash != $passHash) { + // Throw an exception here to stop the proccessing + throw new AccountPasswordMismatchException($this, User::EXCEPTION_USER_PASS_MISMATCH); + } // END - if + } +} + +// [EOF] +?> diff --git a/inc/classes/main/filter/verifier/class_UserStatusVerifierFilter.php b/inc/classes/main/filter/verifier/class_UserStatusVerifierFilter.php new file mode 100644 index 0000000..a9ccbf0 --- /dev/null +++ b/inc/classes/main/filter/verifier/class_UserStatusVerifierFilter.php @@ -0,0 +1,84 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class UserStatusVerifierFilter extends BaseFrameworkSystem implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("A filter for email changes"); + + // Create unique ID number + $this->generateUniqueId(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function createUserStatusVerifierFilter () { + // Get a new instance + $filterInstance = new UserStatusVerifierFilter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get a user instance for comparison + $userInstance = Registry::getRegistry()->getInstance('user'); + + // Is the user account confirmed? + if (($userInstance->getField('user_status') != $this->getConfigInstance()->readConfig('user_status_confirmed')) && ($userInstance->getField('user_status') != $this->getConfigInstance()->readConfig('user_status_guest'))) { + // Request is invalid! + $requestInstance->requestIsValid(false); + + // Redirect to configured URL + $responseInstance->redirectToConfiguredUrl('login_user_status_url'); + + // Stop processing here + exit(); + } // END - if + } +} + +// [EOF] +?> diff --git a/inc/classes/main/resolver/action/.htaccess b/inc/classes/main/resolver/action/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/resolver/action/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/resolver/action/class_BaseActionResolver.php b/inc/classes/main/resolver/action/class_BaseActionResolver.php new file mode 100644 index 0000000..2de5ec7 --- /dev/null +++ b/inc/classes/main/resolver/action/class_BaseActionResolver.php @@ -0,0 +1,138 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class BaseActionResolver extends BaseResolver { + /** + * Prefix for local, remote or other resolver + */ + private $actionPrefix = ""; + + /** + * Validated action name + */ + private $actionName = ""; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } + + /** + * Setter for action prefix + * + * @param $actionPrefix Last validated actionPrefix + * @return void + */ + protected final function setActionPrefix ($actionPrefix) { + $this->actionPrefix = $actionPrefix; + } + + /** + * Setter for action name + * + * @param $actionName Last validated action name + * @return void + */ + protected final function setActionName ($actionName) { + $this->actionName = $actionName; + } + + /** + * Getter for action name + * + * @return $actionName Last validated action name + */ + protected final function getActionName () { + return $this->actionName; + } + + /** + * Checks wether the given action is valid + * + * @param $actionName The default action we shall execute + * @return $isValid Wether the given action is valid + * @throws EmptyVariableException Thrown if the given action is not set + */ + public function isActionValid ($actionName) { + // By default nothing shall be valid + $isValid = false; + + // Is a action set? + if (empty($actionName)) { + // Then thrown an exception here + throw new EmptyVariableException(array($this, 'actionName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } // END - if + + // Now, let us create the full name of the action class + $className = sprintf("%s%sAction", + $this->actionPrefix, + $this->convertToClassName($actionName) + ); + + // Is this class already loaded? + if (class_exists($className)) { + // This class does exist. :-) + $isValid = true; + } // END - if + + // Debug output + //* DEBUG: */ $this->debugBacktrace(); + + // Set action name + $this->setActionName($actionName); + + // Return the result + return $isValid; + } + + /** + * "Loads" current action and instances it if not yet cached + * + * @return $actionInstance A loaded action instance + * @throws InvalidActionException Thrown if even the default + * action class is missing (bad!) + */ + protected function loadAction () { + // Init action instance + $actionInstance = null; + + // Create action class name + $className = sprintf("Web%sAction", + $this->convertToClassName($this->getActionName()) + ); + + // Initiate the action + $actionInstance = ObjectFactory::createObjectByName($className, array($this)); + + // Return the result + return $actionInstance; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/resolver/action/web/.htaccess b/inc/classes/main/resolver/action/web/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/resolver/action/web/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/resolver/action/web/class_WebActionResolver.php b/inc/classes/main/resolver/action/web/class_WebActionResolver.php new file mode 100644 index 0000000..43fda22 --- /dev/null +++ b/inc/classes/main/resolver/action/web/class_WebActionResolver.php @@ -0,0 +1,153 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class WebActionResolver extends BaseActionResolver implements ActionResolver { + /** + * Last successfull resolved action + */ + private $lastActionInstance = ""; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("Resolver for local web actions"); + + // Create unique ID number + $this->generateUniqueId(); + + // Set prefix to "Web" + $this->setActionPrefix("Web"); + } + + /** + * Creates an instance of a Web action resolver with a given default action + * + * @param $actionName The default action we shall execute + * @param $appInstance An instance of a manageable application helper class + * @return $resolverInstance The prepared action resolver instance + * @throws EmptyVariableException Thrown if the default action is not set + * @throws InvalidActionException Thrown if the default action is invalid + */ + public final static function createWebActionResolver ($actionName, ManageableApplication $appInstance) { + // Create the new instance + $resolverInstance = new WebActionResolver(); + + // Is the variable $actionName set and the action is valid? + if (empty($actionName)) { + // Then thrown an exception here + throw new EmptyVariableException(array($resolverInstance, 'defaultAction'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } elseif (!$resolverInstance->isActionValid($actionName)) { + // Invalid action found + throw new InvalidActionException(array($resolverInstance, $actionName), self::EXCEPTION_INVALID_ACTION); + } + + // Set the application instance + $resolverInstance->setApplicationInstance($appInstance); + + // Return the prepared instance + return $resolverInstance; + } + + /** + * Returns an action instance for a given request class or null if + * it was not found + * + * @param $requestInstance An instance of a request class + * @return $actionInstance An instance of the resolved action + * @throws InvalidActionException Thrown if $actionName is + * invalid + * @throws InvalidActionInstanceException Thrown if $actionInstance + * is an invalid instance + */ + public function resolveActionByRequest (Requestable $requestInstance) { + // Init variables + $actionName = ""; + $actionInstance = null; + + // This goes fine so let's resolv the action + $actionName = $requestInstance->getRequestElement('action'); + + // Is the action empty? Then fall back to default action + if (empty($actionName)) $actionName = $this->getConfigInstance()->readConfig('default_action'); + + // Check if the action is valid + if (!$this->isActionValid($actionName)) { + // This action is invalid! + throw new InvalidActionException(array($this, $actionName), self::EXCEPTION_INVALID_ACTION); + } // END - if + + // Get the action + $actionInstance = $this->loadAction(); + + // And validate it + if ((!is_object($actionInstance)) || (!$actionInstance instanceof Actionable)) { + // This action has an invalid instance! + throw new InvalidActionInstanceException(array($this, $actionName), self::EXCEPTION_INVALID_ACTION); + } // END - if + + // Set last action + $this->lastActionInstance = $actionInstance; + + // Return the resolved action instance + return $actionInstance; + } + + /** + * Resolves the action by its direct name and returns an instance of its class + * + * @return $actionInstance An instance of the action class + * @throws InvalidActionException Thrown if $actionName is invalid + */ + public function resolveAction () { + // Initiate the instance variable + $actionInstance = null; + + // Get action name + $actionName = $this->getActionName(); + + // Is the action empty? Then fall back to default action + if (empty($actionName)) $actionName = $this->getConfigInstance()->readConfig('default_action'); + + // Check if the action is valid + if (!$this->isActionValid($actionName)) { + // This action is invalid! + throw new InvalidActionException(array($this, $actionName), self::EXCEPTION_INVALID_ACTION); + } + + // Get the action + $actionInstance = $this->loadAction(); + + // Return the instance + return $actionInstance; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/resolver/class_BaseResolver.php b/inc/classes/main/resolver/class_BaseResolver.php index 6c9ebf7..305b279 100644 --- a/inc/classes/main/resolver/class_BaseResolver.php +++ b/inc/classes/main/resolver/class_BaseResolver.php @@ -22,121 +22,25 @@ * along with this program. If not, see . */ class BaseResolver extends BaseFrameworkSystem { - /** - * Validated command name - */ - private $commandName = ""; - - /** - * Prefix for local, remote or other resolver - */ - private $commandPrefix = ""; - - /** - * A controller instance - */ - private $controllerInstance = null; + // Exception constants + const EXCEPTION_INVALID_COMMAND = 0x0c0; + const EXCEPTION_INVALID_CONTROLLER = 0x0c1; + const EXCEPTION_INVALID_ACTION = 0x0c2; /** * Protected constructor * + * @param $className Real name of the class * @return void */ - protected function __construct ($class) { + protected function __construct ($className) { // Call parent constructor - parent::__construct($class); + parent::__construct($className); // Clean up a little $this->removeNumberFormaters(); $this->removeSystemArray(); } - - /** - * Setter for controller instance (this surely breaks a bit the MVC patterm) - * - * @param $controllerInstance An instance of the controller - * @return void - */ - public final function setControllerInstance (Controller $controllerInstance) { - $this->controllerInstance = $controllerInstance; - } - - /** - * Getter for controller instance (this surely breaks a bit the MVC patterm) - * - * @return $controllerInstance An instance of the controller - */ - public final function getControllerInstance () { - return $this->controllerInstance; - } - - /** - * Setter for command name - * - * @param $commandName Last validated command name - * @return void - */ - protected final function setCommandName ($commandName) { - $this->commandName = $commandName; - } - - /** - * Getter for command name - * - * @return $commandName Last validated command name - */ - protected final function getCommandName () { - return $this->commandName; - } - - /** - * Setter for command prefix - * - * @param $commandPrefix Last validated commandPrefix - * @return void - */ - protected final function setCommandPrefix ($commandPrefix) { - $this->commandPrefix = $commandPrefix; - } - - /** - * Checks wether the given command is valid - * - * @param $commandName The default command we shall execute - * @return $isValid Wether the given command is valid - * @throws EmptyVariableException Thrown if the given command is not set - */ - public function isCommandValid ($commandName) { - // By default nothing shall be valid - $isValid = false; - - // Is a command set? - if (empty($commandName)) { - // Then thrown an exception here - throw new EmptyVariableException(array($this, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } - - // Now, let us create the full name of the command class - $class = sprintf("%s%sCommand", - $this->commandPrefix, - $this->convertToClassName($commandName) - ); - - // Is this class already loaded? - if (class_exists($class)) { - // This class does exist. :-) - $isValid = true; - } - - // Debug output - //* DEBUG: */ $this->debugBacktrace(); - - // Set command name - $this->setCommandName($commandName); - - // Return the result - return $isValid; - } } // [EOF] diff --git a/inc/classes/main/resolver/command/.htaccess b/inc/classes/main/resolver/command/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/resolver/command/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/resolver/command/class_BaseCommandResolver.php b/inc/classes/main/resolver/command/class_BaseCommandResolver.php new file mode 100644 index 0000000..34ccf71 --- /dev/null +++ b/inc/classes/main/resolver/command/class_BaseCommandResolver.php @@ -0,0 +1,139 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class BaseCommandResolver extends BaseResolver { + /** + * Prefix for local, remote or other resolver + */ + private $commandPrefix = ""; + + /** + * Validated command name + */ + private $commandName = ""; + + /** + * A controller instance + */ + private $controllerInstance = null; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } + + /** + * Setter for command prefix + * + * @param $commandPrefix Last validated commandPrefix + * @return void + */ + protected final function setCommandPrefix ($commandPrefix) { + $this->commandPrefix = $commandPrefix; + } + + /** + * Setter for command name + * + * @param $commandName Last validated command name + * @return void + */ + protected final function setCommandName ($commandName) { + $this->commandName = $commandName; + } + + /** + * Getter for command name + * + * @return $commandName Last validated command name + */ + protected final function getCommandName () { + return $this->commandName; + } + + /** + * Setter for controller instance (this surely breaks a bit the MVC patterm) + * + * @param $controllerInstance An instance of the controller + * @return void + */ + public final function setControllerInstance (Controller $controllerInstance) { + $this->controllerInstance = $controllerInstance; + } + + /** + * Getter for controller instance (this surely breaks a bit the MVC patterm) + * + * @return $controllerInstance An instance of the controller + */ + public final function getControllerInstance () { + return $this->controllerInstance; + } + + /** + * Checks wether the given command is valid + * + * @param $commandName The default command we shall execute + * @return $isValid Wether the given command is valid + * @throws EmptyVariableException Thrown if the given command is not set + */ + public function isCommandValid ($commandName) { + // By default nothing shall be valid + $isValid = false; + + // Is a command set? + if (empty($commandName)) { + // Then thrown an exception here + throw new EmptyVariableException(array($this, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } + + // Now, let us create the full name of the command class + $className = sprintf("%s%sCommand", + $this->commandPrefix, + $this->convertToClassName($commandName) + ); + + // Is this class already loaded? + if (class_exists($className)) { + // This class does exist. :-) + $isValid = true; + } // END - if + + // Debug output + //* DEBUG: */ $this->debugBacktrace(); + + // Set command name + $this->setCommandName($commandName); + + // Return the result + return $isValid; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/resolver/web/class_WebCommandResolver.php b/inc/classes/main/resolver/command/class_WebCommandResolver.php similarity index 100% rename from inc/classes/main/resolver/web/class_WebCommandResolver.php rename to inc/classes/main/resolver/command/class_WebCommandResolver.php diff --git a/inc/classes/main/resolver/command/web/.htaccess b/inc/classes/main/resolver/command/web/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/resolver/command/web/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/resolver/command/web/class_WebCommandResolver.php b/inc/classes/main/resolver/command/web/class_WebCommandResolver.php new file mode 100644 index 0000000..d1ee1e6 --- /dev/null +++ b/inc/classes/main/resolver/command/web/class_WebCommandResolver.php @@ -0,0 +1,190 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class WebCommandResolver extends BaseCommandResolver implements CommandResolver { + /** + * Last successfull resolved command + */ + private $lastCommandInstance = ""; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("Resolver for local web commands"); + + // Create unique ID number + $this->generateUniqueId(); + + // Set prefix to "Web" + $this->setCommandPrefix("Web"); + } + + /** + * Creates an instance of a Web command resolver with a given default command + * + * @param $commandName The default command we shall execute + * @param $appInstance An instance of a manageable application helper class + * @return $resolverInstance The prepared command resolver instance + * @throws EmptyVariableException Thrown if the default command is not set + * @throws InvalidCommandException Thrown if the default command is invalid + */ + public final static function createWebCommandResolver ($commandName, ManageableApplication $appInstance) { + // Create the new instance + $resolverInstance = new WebCommandResolver(); + + // Is the variable $commandName set and the command is valid? + if (empty($commandName)) { + // Then thrown an exception here + throw new EmptyVariableException(array($resolverInstance, 'defaultCommand'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } elseif (!$resolverInstance->isCommandValid($commandName)) { + // Invalid command found + throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND); + } + + // Set the application instance + $resolverInstance->setApplicationInstance($appInstance); + + // Return the prepared instance + return $resolverInstance; + } + + /** + * Returns an command instance for a given request class or null if + * it was not found + * + * @param $requestInstance An instance of a request class + * @return $commandInstance An instance of the resolved command + * @throws InvalidCommandException Thrown if $commandName is + * invalid + * @throws InvalidCommandInstanceException Thrown if $commandInstance + * is an invalid instance + */ + public function resolveCommandByRequest (Requestable $requestInstance) { + // Init variables + $commandName = ""; + $commandInstance = null; + + // This goes fine so let's resolv the command + $commandName = $requestInstance->getRequestElement('page'); + + // Is the command empty? Then fall back to default command + if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_command'); + + // Check if the command is valid + if (!$this->isCommandValid($commandName)) { + // This command is invalid! + throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); + } // END - if + + // Get the command + $commandInstance = $this->loadCommand($commandName); + + // And validate it + if ((!is_object($commandInstance)) || (!$commandInstance instanceof Commandable)) { + // This command has an invalid instance! + throw new InvalidCommandInstanceException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); + } // END - if + + // Set last command + $this->lastCommandInstance = $commandInstance; + + // Return the resolved command instance + return $commandInstance; + } + + /** + * Resolves the command by its direct name and returns an instance of its class + * + * @param $commandName The direct command name we shall resolve + * @return $commandInstance An instance of the command class + * @throws InvalidCommandException Thrown if $commandName is invalid + */ + public function resolveCommand ($commandName) { + // Initiate the instance variable + $commandInstance = null; + + // Is the command empty? Then fall back to default command + if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_command'); + + // Check if the command is valid + if (!$this->isCommandValid($commandName)) { + // This command is invalid! + throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); + } + + // Get the command + $commandInstance = $this->loadCommand($commandName); + + // Return the instance + return $commandInstance; + } + + /** + * "Loads" a given command and instances it if not yet cached + * + * @param $commandName A command name we shall look for + * @return $commandInstance A loaded command instance + * @throws InvalidCommandException Thrown if even the default + * command class is missing (bad!) + */ + private function loadCommand ($commandName) { + // Cache default command + $defaultCommand = $this->getConfigInstance()->readConfig('default_command'); + + // Init command instance + $commandInstance = null; + + // Create command class name + $className = sprintf("Web%sCommand", + $this->convertToClassName($commandName) + ); + + // Is this class loaded? + if (!class_exists($className)) { + // Class not found, so try the default one or throw exception + if ($commandName != $defaultCommand) { + // Try the default command + return $this->loadCommand($defaultCommand); + } else { + // Still not found? + throw new InvalidCommandException(array($this, $defaultCommand), self::EXCEPTION_INVALID_COMMAND); + } + } // END - if + + // Initiate the command + $commandInstance = ObjectFactory::createObjectByName($className, array($this)); + + // Return the result + return $commandInstance; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/resolver/controller/.htaccess b/inc/classes/main/resolver/controller/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/resolver/controller/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/resolver/controller/class_BaseControllerResolver.php b/inc/classes/main/resolver/controller/class_BaseControllerResolver.php new file mode 100644 index 0000000..f584975 --- /dev/null +++ b/inc/classes/main/resolver/controller/class_BaseControllerResolver.php @@ -0,0 +1,128 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class BaseControllerResolver extends BaseResolver { + /** + * Prefix for local, remote or other resolver + */ + private $controllerPrefix = ""; + + /** + * Validated controller name + */ + private $controllerName = ""; + + /** + * Protected constructor + * + * @param $className Name of the real class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } + + /** + * Setter for controller prefix + * + * @param $controllerPrefix Last validated controllerPrefix + * @return void + */ + protected final function setControllerPrefix ($controllerPrefix) { + $this->controllerPrefix = $controllerPrefix; + } + + /** + * Setter for controller name + * + * @param $controllerName Last validated controller name + * @return void + */ + protected final function setControllerName ($controllerName) { + $this->controllerName = $controllerName; + } + + /** + * Getter for controller name + * + * @return $controllerName Last validated controller name + */ + protected final function getControllerName () { + return $this->controllerName; + } + + /** + * Checks wether the given controller is valid + * + * @param $controllerName The default controller we shall execute + * @return $isValid Wether the given controller is valid + * @throws EmptyVariableException Thrown if the given controller is not set + */ + public function isControllerValid ($controllerName) { + // By default nothing shall be valid + $isValid = false; + + // Is a controller set? + if (empty($controllerName)) { + // Then thrown an exception here + throw new EmptyVariableException(array($this, 'controllerName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } // END - if + + // Now, let us create the full name of the controller class + $className = sprintf("%s%sController", + $this->controllerPrefix, + $this->convertToClassName($controllerName) + ); + + // Try it hard to get an controller + while (!$isValid) { + // Is this class already loaded? + if (class_exists($className)) { + // This class does exist. :-) + $isValid = true; + } elseif (($className != "WebDefaultController") && ($className != "WebDefaultNewsController")) { + // Do we have news? + if ($this->getConfigInstance()->readConfig('page_with_news') == $this->getApplicationInstance()->getRequestInstance()->getRequestElement('page')) { + // Yes, display news in home then set default controller with news + $className = "WebDefaultNewsController"; + } else { + // No news at "home" page or non-news page + $className = "WebDefaultController"; + } + } else { + // All is tried, give it up here + throw new DefaultControllerException($this, self::EXCEPTION_DEFAUL_CONTROLLER_GONE); + } + } // END - while + + // Debug output + //* DEBUG: */ $this->debugBacktrace(); + + // Return the result + return $isValid; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/resolver/controller/web/.htaccess b/inc/classes/main/resolver/controller/web/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/resolver/controller/web/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/resolver/web/class_WebControllerResolver.php b/inc/classes/main/resolver/controller/web/class_WebControllerResolver.php similarity index 67% rename from inc/classes/main/resolver/web/class_WebControllerResolver.php rename to inc/classes/main/resolver/controller/web/class_WebControllerResolver.php index a02eeaa..eec9884 100644 --- a/inc/classes/main/resolver/web/class_WebControllerResolver.php +++ b/inc/classes/main/resolver/controller/web/class_WebControllerResolver.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class WebControllerResolver extends BaseResolver implements ControllerResolver { +class WebControllerResolver extends BaseControllerResolver implements ControllerResolver { /** * Last successfull resolved controller (name) */ @@ -48,34 +48,37 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { $this->generateUniqueId(); // Set prefix to "Web" - $this->setCommandPrefix("Web"); + $this->setControllerPrefix("Web"); } /** * Creates an instance of a resolver class with a given command * - * @param $commandName The default command we shall execute + * @param $controllerName The controller we shall resolve * @param $appInstance An instance of a manageable application helper class - * @return $resolverInstance The prepared command resolver instance + * @return $resolverInstance The prepared controller resolver instance * @throws EmptyVariableException Thrown if the default command is not set - * @throws InvalidCommandException Thrown if the default command is invalid + * @throws InvalidControllerException Thrown if the default controller is invalid */ - public final static function createWebControllerResolver ($commandName, ManageableApplication $appInstance) { + public final static function createWebControllerResolver ($controllerName, ManageableApplication $appInstance) { // Create the new instance $resolverInstance = new WebControllerResolver(); - // Is the variable $commandName set and the command is valid? - if (empty($commandName)) { + // Is the variable $controllerName set and the command is valid? + if (empty($controllerName)) { // Then thrown an exception here throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } elseif (!$resolverInstance->isCommandValid($commandName)) { + } elseif (!$resolverInstance->isControllerValid($controllerName)) { // Invalid command found - throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND); + throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_COMMAND); } // Set the application instance $resolverInstance->setApplicationInstance($appInstance); + // Set command name + $resolverInstance->setControllerName($controllerName); + // Return the prepared instance return $resolverInstance; } @@ -85,32 +88,24 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { * * @return $controllerInstance A controller instance for the default * command - * @throws InvalidCommandException Thrown if $commandName is - * invalid - * @throws InvalidControllerInstanceException Thrown if $commandInstance + * @throws InvalidControllerInstanceException Thrown if $controllerInstance * is invalid */ - public function resolveCommandController () { + public function resolveController () { // Init variables - $commandName = ""; + $controllerName = ""; $controllerInstance = null; // Get the command name - $commandName = $this->getCommandName(); - - // Check if the command is valid - if (!$this->isCommandValid($commandName)) { - // This command is invalid! - throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); - } // END - if + $controllerName = $this->getControllerName(); // Get the command - $controllerInstance = $this->loadController($commandName); + $controllerInstance = $this->loadController($controllerName); // And validate it if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) { // This command has an invalid instance! - throw new InvalidControllerInstanceException(array($this, $commandName), self::EXCEPTION_INVALID_CONTROLLER); + throw new InvalidControllerInstanceException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER); } // END - if // Set last controller @@ -125,46 +120,46 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { * controller was not found one of the default controllers will be used * depending on wether news shall be displayed. * - * @param $commandName A controller name we shall look for + * @param $controllerName A controller name we shall look for * @return $controllerInstance A loaded controller instance * @throws DefaultControllerException Thrown if even the default * controller class is missing (bad!) */ - private function loadController ($commandName) { + private function loadController ($controllerName) { // Debug message //* DEBUG: */ $this->debugBacktrace(); // Cache default command - $defaultCommand = $this->getConfigInstance()->readConfig('default_command'); + $defaultController = $this->getConfigInstance()->readConfig('default_command'); // Init controller instance $controllerInstance = null; // Default controller - $class = "WebDefaultController"; + $className = "WebDefaultController"; // Generate the class name - //* DEBUG: */ echo __METHOD__.": Command=".$commandName; - if ($commandName != $defaultCommand) { + //* DEBUG: */ echo __METHOD__.": Controller=".$controllerName; + if ($controllerName != $defaultController) { // Create controller class name - $class = sprintf("Web%sController", - $this->convertToClassName($commandName) + $className = sprintf("Web%sController", + $this->convertToClassName($controllerName) ); } elseif ($this->getConfigInstance()->readConfig('page_with_news') == $this->getApplicationInstance()->getRequestInstance()->getRequestElement('page')) { // Yes, display news in home then set default controller with news - $class = "WebDefaultNewsController"; + $className = "WebDefaultNewsController"; } else { // No news at "home" page or non-news page - $class = "WebDefaultController"; + $className = "WebDefaultController"; } - //* DEBUG: */ echo ", controller=".$class."
\n"; + //* DEBUG: */ echo ", controller=".$className."
\n"; // Is this class loaded? - if (!class_exists($class)) { + if (!class_exists($className)) { // Class not found, so try the default one or throw exception - if ($commandName != $defaultCommand) { + if ($controllerName != $defaultController) { // Try the default controller - return $this->loadController($defaultCommand); + return $this->loadController($defaultController); } else { // Still not found? throw new DefaultControllerException($this, self::EXCEPTION_DEFAUL_CONTROLLER_GONE); @@ -172,8 +167,8 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { } // END - if // Initiate the resolver and controller - $resolverInstance = ObjectFactory::createObjectByConfiguredName('web_cmd_resolver_class', array($commandName, $this->getApplicationInstance())); - $controllerInstance = ObjectFactory::createObjectByName($class, array($resolverInstance)); + $resolverInstance = ObjectFactory::createObjectByConfiguredName('web_cmd_resolver_class', array($controllerName, $this->getApplicationInstance())); + $controllerInstance = ObjectFactory::createObjectByName($className, array($resolverInstance)); // Remove resolver unset($resolverInstance); diff --git a/inc/config.php b/inc/config.php index 131af0a..0bdd034 100644 --- a/inc/config.php +++ b/inc/config.php @@ -185,7 +185,7 @@ $cfg->setConfigEntry('username_is_guest_class', "UserNameIsGuestFilter"); // CFG: PASSWORD-VALIDATOR $cfg->setConfigEntry('password_validator_class', "PasswordValidatorFilter"); -// CFG: RULES-ACCEPTED-FILTER +// CFG: RULES-ACCEPTED-CLASS $cfg->setConfigEntry('rules_accepted_class', "RulesAcceptedFilter"); // CFG: USERNAME-VERIFIER @@ -200,9 +200,15 @@ $cfg->setConfigEntry('password_verifier_class', "PasswordVerifierFilter"); // CFG: EMAIL-CHANGE-CLASS $cfg->setConfigEntry('email_change_class', "EmailChangeFilter"); -// CFG: PASSWORD-CHANGE-FILTER +// CFG: PASSWORD-CHANGE-CLASS $cfg->setConfigEntry('password_change_class', "PasswordChangeFilter"); +// CFG: ACCOUNT-PASSWORD-CLASS +$cfg->setConfigEntry('account_password_class', "AccountPasswordVerifierFilter"); + +// CFG: USER-STATUS-CLASS +$cfg->setConfigEntry('user_status_class', "UserStatusVerifierFilter"); + // CFG: CRYPTO-HELPER $cfg->setConfigEntry('crypto_class', "CryptoHelper"); -- 2.39.2