From 35546efaf0eb7ea9563b27b0f0f9a8aca2a1ea15 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 31 Jul 2009 19:49:14 +0000 Subject: [PATCH] Several entries fixed/renamed (sory, lame text) --- .gitattributes | 5 + application/ship-simu/config.php | 21 +- .../main/commands/web/company/.htaccess | 1 + .../class_WebShipSimuCompanyCommand.php | 92 +++++++++ .../web/class_WebCompanyController.php | 106 ++++++++++ .../main/menu/class_ShipSimuLogoutMenu.php | 50 +++++ .../web/class_WebCompanyCommandResolver.php | 190 ++++++++++++++++++ ...ass_WebGovernmentFailedCommandResolver.php | 5 +- .../code/action_ship_simu_login_company.ctp | 4 +- .../templates/de/code/login_form.ctp | 4 +- 10 files changed, 469 insertions(+), 9 deletions(-) create mode 100644 application/ship-simu/main/commands/web/company/.htaccess create mode 100644 application/ship-simu/main/commands/web/company/class_WebShipSimuCompanyCommand.php create mode 100644 application/ship-simu/main/controller/web/class_WebCompanyController.php create mode 100644 application/ship-simu/main/menu/class_ShipSimuLogoutMenu.php create mode 100644 application/ship-simu/main/resolver/web/class_WebCompanyCommandResolver.php diff --git a/.gitattributes b/.gitattributes index c434ba1..523633a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -92,6 +92,8 @@ application/ship-simu/main/commands/web/class_WebShipsimuProfileCommand.php -tex application/ship-simu/main/commands/web/class_WebShipsimuRefillCommand.php -text application/ship-simu/main/commands/web/class_WebShipsimuRegisterCommand.php -text application/ship-simu/main/commands/web/class_WebShipsimuUserLoginCommand.php -text +application/ship-simu/main/commands/web/company/.htaccess -text +application/ship-simu/main/commands/web/company/class_WebShipSimuCompanyCommand.php -text application/ship-simu/main/commands/web/government/.htaccess -text application/ship-simu/main/commands/web/government/class_WebGovernmentFailedStartupCommand.php -text application/ship-simu/main/commands/web/government/class_WebShipsimuGovernmentStartupCommand.php -text @@ -111,6 +113,7 @@ application/ship-simu/main/constructions/yards/.htaccess -text application/ship-simu/main/constructions/yards/class_Shipyard.php -text application/ship-simu/main/controller/.htaccess -text application/ship-simu/main/controller/web/.htaccess -text +application/ship-simu/main/controller/web/class_WebCompanyController.php -text application/ship-simu/main/controller/web/class_WebGovernmentFailedController.php -text application/ship-simu/main/drives/.htaccess -text application/ship-simu/main/drives/class_BaseDrive.php -text @@ -145,6 +148,7 @@ application/ship-simu/main/menu/class_ShipSimu -text application/ship-simu/main/menu/class_ShipSimuHomeMenu.php -text application/ship-simu/main/menu/class_ShipSimuLoginAreaMenu.php -text application/ship-simu/main/menu/class_ShipSimuLoginMenu.php -text +application/ship-simu/main/menu/class_ShipSimuLogoutMenu.php -text application/ship-simu/main/menu/class_ShipSimuRegisterMenu.php -text application/ship-simu/main/parts/.htaccess -text application/ship-simu/main/parts/class_BaseShipPart.php -text @@ -158,6 +162,7 @@ application/ship-simu/main/registration/.htaccess -text application/ship-simu/main/registration/class_ShipSimuRegistration.php -text application/ship-simu/main/resolver/.htaccess -text application/ship-simu/main/resolver/web/.htaccess -text +application/ship-simu/main/resolver/web/class_WebCompanyCommandResolver.php -text application/ship-simu/main/resolver/web/class_WebGovernmentFailedCommandResolver.php -text application/ship-simu/main/ships/.htaccess -text application/ship-simu/main/ships/class_BaseShip.php -text diff --git a/application/ship-simu/config.php b/application/ship-simu/config.php index 6e77dcc..8c7ad1a 100644 --- a/application/ship-simu/config.php +++ b/application/ship-simu/config.php @@ -134,13 +134,22 @@ $cfg->setConfigEntry('refill_page_done_url', "index.php?app={?app_short_name?}&p $cfg->setConfigEntry('login_default_action', "welcome"); // CFG: LOGIN-AREA-LOGOUT-ACTION -$cfg->setConfigEntry('login_area_logout_action', "logout"); +$cfg->setConfigEntry('login_area_logout_action', "index.php?app={?app_short_name?}&page=login_area&page=logout"); // CFG: LOGIN-AREA-PROFILE-ACTION -$cfg->setConfigEntry('login_area_profile_action', "profile"); +$cfg->setConfigEntry('login_area_profile_action', "index.php?app={?app_short_name?}&page=login_area&page=profile"); // CFG: LOGIN-AREA-COMPANY-ACTION -$cfg->setConfigEntry('login_area_company_action', "company"); +$cfg->setConfigEntry('login_area_company_action', "index.php?app={?app_short_name?}&page=login_area"); + +// CFG: LOGIN-AREA-LIST-COMPANIES-ACTION +$cfg->setConfigEntry('login_area_list_companies_action', "index.php?app={?app_short_name?}&page=login_area"); + +// CFG: LOGOUT_DONE-RELOGIN-ACTION +$cfg->setConfigEntry('logout_done_relogin_action', "index.php?app={?app_short_name?}&page=login"); + +// CFG: LOGIN-REGISTER-ACTION +$cfg->setConfigEntry('login_register_action', "index.php?app={?app_short_name?}&page=register"); // CFG: NEWS-READER-HOME-CLASS $cfg->setConfigEntry('news_reader_home_class', "DefaultNewsReader"); @@ -403,6 +412,9 @@ $cfg->setConfigEntry('web_link_helper', "WebLinkHelper"); // CFG: WEB-CMD-GOVERNMENT-FAILED-RESOLVER-CLASS $cfg->setConfigEntry('web_cmd_government_failed_resolver_class', "WebGovernmentFailedCommandResolver"); +// CFG: WEB-CMD-COMPANY-RESOLVER-CLASS +$cfg->setConfigEntry('web_cmd_company_resolver_class', "WebCompanyCommandResolver"); + // CFG: REFILL-REQUEST-CURRENCY-PAYMENT-TYPE $cfg->setConfigEntry('refill_request_currency_payment_type', "test"); @@ -415,6 +427,9 @@ $cfg->setConfigEntry('home_menu_class', "ShipSimuHomeMenu"); // CFG: LOGIN-MENU-CLASS $cfg->setConfigEntry('login_menu_class', "ShipSimuLoginMenu"); +// CFG: LOGOUT-MENU-CLASS +$cfg->setConfigEntry('logout_menu_class', "ShipSimuLogoutMenu"); + // CFG: REGISTER-MENU-CLASS $cfg->setConfigEntry('register_menu_class', "ShipSimuRegisterMenu"); diff --git a/application/ship-simu/main/commands/web/company/.htaccess b/application/ship-simu/main/commands/web/company/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/ship-simu/main/commands/web/company/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/ship-simu/main/commands/web/company/class_WebShipSimuCompanyCommand.php b/application/ship-simu/main/commands/web/company/class_WebShipSimuCompanyCommand.php new file mode 100644 index 0000000..63d4652 --- /dev/null +++ b/application/ship-simu/main/commands/web/company/class_WebShipSimuCompanyCommand.php @@ -0,0 +1,92 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu Developer Team + * @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 WebShipSimuCompanyCommand extends BaseCommand implements Commandable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Creates an instance of this command and sets the resolver instance + * + * @param $resolverInstance An instance of a command resolver + * @return $commandInstance The created command instance + */ + public final static function createWebShipSimuCompanyCommand (CommandResolver $resolverInstance) { + // Get a new instance + $commandInstance = new WebShipSimuCompanyCommand(); + + // Set the resolver instance + $commandInstance->setResolverInstance($resolverInstance); + + // Return the prepared instance + return $commandInstance; + } + + /** + * 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) { + // Get template instance + $templateInstance = $responseInstance->getTemplateInstance(); + + // Set amount and type as variables + $templateInstance->assignVariable('refill_done', $requestInstance->getRequestElement('type')); + $templateInstance->assignVariable('amount' , $requestInstance->getRequestElement('amount')); + + // This method does currently redirect if all goes right + $responseInstance->redirectToConfiguredUrl('refill_page_done'); + } + + /** + * 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 auth filter (we don't need an update of the user here because it will be redirected) + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_auth_filter')); + + // Add user status filter here + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_status_filter')); + } +} + +// [EOF] +?> diff --git a/application/ship-simu/main/controller/web/class_WebCompanyController.php b/application/ship-simu/main/controller/web/class_WebCompanyController.php new file mode 100644 index 0000000..6cd2c44 --- /dev/null +++ b/application/ship-simu/main/controller/web/class_WebCompanyController.php @@ -0,0 +1,106 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu Developer Team + * @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 WebCompanyController extends BaseController implements Controller { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @param $resolverInstance An instance of a command resolver class + * @return $controllerInstance A prepared instance of this class + * @todo Add some filters to this controller + */ + public final static function createWebCompanyController (CommandResolver $resolverInstance) { + // Create the instance + $controllerInstance = new WebCompanyController(); + + // Set the command resolver + $controllerInstance->setResolverInstance($resolverInstance); + + // User auth filter + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_auth_filter')); + + // User update filter + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_update_filter')); + + // News fetcher filter + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_download_filter')); + + // News proccess/display-preparation + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_process_filter')); + + // Return the prepared instance + return $controllerInstance; + } + + /** + * Handles the given request and response + * + * @param $requestInstance An instance of a request class + * @param $responseInstance An instance of a response class + * @return void + */ + 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()->resolveCommandByRequest($requestInstance); + + // Add more filters by the command + $commandInstance->addExtraFilters($this, $requestInstance); + + // Try to run the pre filters, if auth exceptions come through redirect here + try { + // Run the pre filters + $this->executePreFilters($requestInstance, $responseInstance); + } catch (UserAuthorizationException $e) { + // Redirect to main page + $responseInstance->redirectToConfiguredUrl('login_failed'); + + // Exit here + exit(); + } + + // This request was valid! :-D + $requestInstance->requestIsValid(); + + // Execute the command + $commandInstance->execute($requestInstance, $responseInstance); + + // Run the pre filters + $this->executePostFilters($requestInstance, $responseInstance); + + // Flush the response out + $responseInstance->flushBuffer(); + } +} + +// [EOF] +?> diff --git a/application/ship-simu/main/menu/class_ShipSimuLogoutMenu.php b/application/ship-simu/main/menu/class_ShipSimuLogoutMenu.php new file mode 100644 index 0000000..f28d6a7 --- /dev/null +++ b/application/ship-simu/main/menu/class_ShipSimuLogoutMenu.php @@ -0,0 +1,50 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu Developer Team + * @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 ShipSimuLogoutMenu extends BaseMenu implements RenderableMenu { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $menuInstance An instance of this class + */ + public final static function createShipSimuLogoutMenu () { + // Get a new instance + $menuInstance = new ShipSimuLogoutMenu(); + + // Return the prepared instance + return $menuInstance; + } +} + +// [EOF] +?> diff --git a/application/ship-simu/main/resolver/web/class_WebCompanyCommandResolver.php b/application/ship-simu/main/resolver/web/class_WebCompanyCommandResolver.php new file mode 100644 index 0000000..c560d4f --- /dev/null +++ b/application/ship-simu/main/resolver/web/class_WebCompanyCommandResolver.php @@ -0,0 +1,190 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu Developer Team + * @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 WebCompanyCommandResolver extends BaseCommandResolver implements CommandResolver { + /** + * Last successfull resolved command + */ + private $lastCommandInstance = null; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // 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 default command is not set + * @throws InvalidInterfaceException Thrown if command does not implement interface Commandable + */ + public final static function createWebCompanyCommandResolver ($commandName, ManageableApplication $appInstance) { + // Create the new instance + $resolverInstance = new WebCompanyCommandResolver(); + + // Get request instance + $requestInstance = $appInstance->getRequestInstance(); + + // Is the variable $commandName set and the command is valid? + if (empty($commandName)) { + // Then thrown an exception here + throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } elseif (!$resolverInstance->resolveCommandByRequest($requestInstance) instanceof Commandable) { + // Invalid command found (missing interface?) + throw new InvalidInterfaceException(array($userInstance, 'ManageableMember'), self::EXCEPTION_REQUIRED_INTERFACE_MISSING); + } + + // 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 instance + $commandInstance = null; + + // This goes fine so let's resolv the command + $commandName = str_replace('-', '_', $requestInstance->getRequestElement('app')) . '_' . $requestInstance->getRequestElement('page'); + + // Is there a "failed" request? + if ($requestInstance->isRequestElementSet('failed')) { + // Then include with within the command name + $commandName = $commandName . '_' . $requestInstance->getRequestElement('failed'); + } // END - if + + // Is the command empty? Then fall back to default command + if (empty($commandName)) $commandName = $this->getConfigInstance()->getConfigEntry('default_web_command'); + + // Check if command is valid + if ($this->isCommandValid($commandName) === false) { + // 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()->getConfigEntry('default_web_command'); + + // Check if command is valid + if ($this->isCommandValid($commandName) === false) { + // 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()->getConfigEntry('default_web_command'); + + // Init command instance + $commandInstance = null; + + // Get 'app' from the application + $app = Registry::getRegistry()->getInstance('application')->getRequestInstance()->getRequestElement('app'); + + // Create command class name + $this->setClassName(sprintf("%s%sCommand", + $this->getCommandPrefix(), + $this->convertToClassName($commandName) + )); + + // Is this class loaded? + if (!class_exists($this->getClassName())) { + // Class not found, so throw an exception + throw new InvalidCommandException(array($this, $defaultCommand), self::EXCEPTION_INVALID_COMMAND); + } // END - if + + // Initiate the command + $commandInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this)); + + // Return the result + return $commandInstance; + } +} + +// [EOF] +?> diff --git a/application/ship-simu/main/resolver/web/class_WebGovernmentFailedCommandResolver.php b/application/ship-simu/main/resolver/web/class_WebGovernmentFailedCommandResolver.php index 27c8a8e..592e1a1 100644 --- a/application/ship-simu/main/resolver/web/class_WebGovernmentFailedCommandResolver.php +++ b/application/ship-simu/main/resolver/web/class_WebGovernmentFailedCommandResolver.php @@ -37,7 +37,7 @@ class WebGovernmentFailedCommandResolver extends BaseCommandResolver implements parent::__construct(__CLASS__); // Set prefix to "Web" - $this->setCommandPrefix("Web"); + $this->setCommandPrefix('Web'); } /** @@ -164,7 +164,8 @@ class WebGovernmentFailedCommandResolver extends BaseCommandResolver implements $commandInstance = null; // Create command class name - $this->setClassName(sprintf("Web%sCommand", + $this->setClassName(sprintf("%s%sCommand", + $this->getCommandPrefix(), $this->convertToClassName($commandName) )); diff --git a/application/ship-simu/templates/de/code/action_ship_simu_login_company.ctp b/application/ship-simu/templates/de/code/action_ship_simu_login_company.ctp index 64d8847..6e824d4 100644 --- a/application/ship-simu/templates/de/code/action_ship_simu_login_company.ctp +++ b/application/ship-simu/templates/de/code/action_ship_simu_login_company.ctp @@ -1,6 +1,6 @@ prefetchValueInstance('user'); @@ -85,6 +85,6 @@ $linkInstance->flushContent(); diff --git a/application/ship-simu/templates/de/code/login_form.ctp b/application/ship-simu/templates/de/code/login_form.ctp index 40af9de..ae60048 100644 --- a/application/ship-simu/templates/de/code/login_form.ctp +++ b/application/ship-simu/templates/de/code/login_form.ctp @@ -70,7 +70,7 @@ if ($helperInstance->ifGuestLoginAllowed()) { } // Get helper instance -$helperInstance = ObjectFactory::createObjectByConfiguredName('web_link_helper', array($this, 'register_login_form')); +$helperInstance = ObjectFactory::createObjectByConfiguredName('web_link_helper', array($this, 'register')); // Set link text $helperInstance->addLinkWithTextById('register_login'); @@ -95,5 +95,5 @@ $helperInstance->flushContent(); -- 2.39.5