From: Roland Häder Date: Thu, 19 Jun 2008 17:11:54 +0000 (+0000) Subject: Logout procedure basicly finished, login area splitted in main and action-dependent... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c983485aaafb177a8dd366a7f7c0fd5db6720d55;p=shipsimu.git Logout procedure basicly finished, login area splitted in main and action-dependent templates --- diff --git a/.gitattributes b/.gitattributes index 3fe37b7..84cffb0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -56,6 +56,7 @@ application/ship-simu/loader.php -text application/ship-simu/main/.htaccess -text application/ship-simu/main/actions/.htaccess -text application/ship-simu/main/actions/class_ShipSimuLoginAction.php -text +application/ship-simu/main/actions/class_ShipSimuLogoutAction.php -text application/ship-simu/main/class_ -text application/ship-simu/main/class_BasePersonell.php -text application/ship-simu/main/class_BaseSimulator.php -text @@ -134,7 +135,10 @@ application/ship-simu/templates/de/code/header.ctp -text application/ship-simu/templates/de/code/home.ctp -text application/ship-simu/templates/de/code/login_failed.ctp -text application/ship-simu/templates/de/code/login_form.ctp -text +application/ship-simu/templates/de/code/login_logout.ctp -text +application/ship-simu/templates/de/code/login_main.ctp -text application/ship-simu/templates/de/code/login_welcome.ctp -text +application/ship-simu/templates/de/code/logout_done.ctp -text application/ship-simu/templates/de/code/register_form.ctp -text application/ship-simu/templates/de/code/shipsimu_main.ctp -text application/ship-simu/templates/de/html/.htaccess -text @@ -334,6 +338,7 @@ inc/classes/main/commands/web/class_WebHomeCommand.php -text inc/classes/main/commands/web/class_WebLoginAreaCommand.php -text inc/classes/main/commands/web/class_WebLoginCommand.php -text inc/classes/main/commands/web/class_WebLoginFailedCommand.php -text +inc/classes/main/commands/web/class_WebLogoutDoneCommand.php -text inc/classes/main/commands/web/class_WebRegisterCommand.php -text inc/classes/main/compressor/.htaccess -text inc/classes/main/compressor/class_Bzip2Compressor.php -text diff --git a/application/selector/class_ApplicationSelector.php b/application/selector/class_ApplicationSelector.php index 928fcda..be289bf 100644 --- a/application/selector/class_ApplicationSelector.php +++ b/application/selector/class_ApplicationSelector.php @@ -315,9 +315,9 @@ class ApplicationSelector extends BaseFrameworkSystem { * @throws NullPointerException If $curr is null * @throws NoArrayException If $curr is not an array * @throws InvalidArrayCountException If $curr contains an - * unexpected count of elements + * unexpected count of elements * @throws MissingArrayElementsException If $curr is missing expected - * array elements + * array elements */ public function insertApplicationTemplates () { // First prepare the instance diff --git a/application/ship-simu/config.php b/application/ship-simu/config.php index 9c000d8..cba02a1 100644 --- a/application/ship-simu/config.php +++ b/application/ship-simu/config.php @@ -88,6 +88,9 @@ $cfg->setConfigEntry('app_login_url', "index.php?app=ship-simu&page=login_area") // CFG: LOGIN-FAILED-URL $cfg->setConfigEntry('login_failed_url', "index.php?app=ship-simu&page=login_failed"); +// CFG: LOGOUT-DONE-URL +$cfg->setConfigEntry('logout_done_url', "index.php?app=ship-simu&page=logout_done"); + // CFG: LOGIN-DEFAULT-ACTION $cfg->setConfigEntry('login_default_action', "welcome"); @@ -133,5 +136,11 @@ $cfg->setConfigEntry('guest_login_password', "guest"); // CFG: LOGIN-WELCOME-ACTION-CLASS $cfg->setConfigEntry('login_welcome_action_class', "ShipSimuLoginAction"); +// CFG: LOGIN-LOGOUT-ACTION-CLASS +$cfg->setConfigEntry('login_logout_action_class', "ShipSimuLogoutAction"); + +// CFG: LOGOUT-IMMEDIATE +$cfg->setConfigEntry('logout_immediate', "N"); + // [EOF] ?> diff --git a/application/ship-simu/main/actions/class_ShipSimuLogoutAction.php b/application/ship-simu/main/actions/class_ShipSimuLogoutAction.php new file mode 100644 index 0000000..e1c0014 --- /dev/null +++ b/application/ship-simu/main/actions/class_ShipSimuLogoutAction.php @@ -0,0 +1,80 @@ + + * @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 ShipSimuLogoutAction extends BaseAction implements Commandable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set description + $this->setObjectDescription("Logout action"); + + // Generate unique key + $this->generateUniqueId(); + } + + /** + * Creates an instance of this action + * + * @return $actionInstance An instance of this action class + */ + public final static function createShipSimuLogoutAction () { + // Get a new instance + $actionInstance = new ShipSimuLogoutAction(); + + // 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) { + // Shall we logout or display logout page or logout immediately? + if (($this->getConfigInstance()->readConfig('logout_immediate') == "Y") || ($requestInstance->isRequestElementSet('logout'))) { + // Get an auth instance for checking and updating the auth cookies + $authInstance = ObjectFactory::createObjectByConfiguredName('auth_method_class', array($responseInstance)); + + // Set request instance + $authInstance->setRequestInstance($requestInstance); + + // Destroy the auth data + $authInstance->destroyAuthData(); + + // Redirect to "logout done" page + $responseInstance->redirectToConfiguredUrl('logout_done_url'); + } // END - if + } +} + +// [EOF] +?> diff --git a/application/ship-simu/templates/de/code/login_failed.ctp b/application/ship-simu/templates/de/code/login_failed.ctp index 5ed3cbb..e823120 100644 --- a/application/ship-simu/templates/de/code/login_failed.ctp +++ b/application/ship-simu/templates/de/code/login_failed.ctp @@ -19,5 +19,6 @@ diff --git a/application/ship-simu/templates/de/code/login_logout.ctp b/application/ship-simu/templates/de/code/login_logout.ctp new file mode 100644 index 0000000..e0eb6d6 --- /dev/null +++ b/application/ship-simu/templates/de/code/login_logout.ctp @@ -0,0 +1,8 @@ +
+
+ Willst du dich wirklich aus dem Spiel aussloggen? +
+ +
diff --git a/application/ship-simu/templates/de/code/login_main.ctp b/application/ship-simu/templates/de/code/login_main.ctp new file mode 100644 index 0000000..3f7cf5f --- /dev/null +++ b/application/ship-simu/templates/de/code/login_main.ctp @@ -0,0 +1,25 @@ +
+ Willkommen im Loginbereich von {?app_full_name?}! +
+ +
+ {?login_content?} +
+ +
+
+ Account-Infos: +
+ {?persona_data?} + +
+ +
+
+ Reederei-Infos: +
+ {?company_data?} +
diff --git a/application/ship-simu/templates/de/code/login_welcome.ctp b/application/ship-simu/templates/de/code/login_welcome.ctp index 7d3df54..64c04da 100644 --- a/application/ship-simu/templates/de/code/login_welcome.ctp +++ b/application/ship-simu/templates/de/code/login_welcome.ctp @@ -1,7 +1,3 @@ -
- Willkommen im Loginbereich von {?app_full_name?} -
-
{?ship_simu_login_news?}
diff --git a/application/ship-simu/templates/de/code/logout_done.ctp b/application/ship-simu/templates/de/code/logout_done.ctp new file mode 100644 index 0000000..9d441da --- /dev/null +++ b/application/ship-simu/templates/de/code/logout_done.ctp @@ -0,0 +1,7 @@ +
+ Du bist jetzt aus dem Spiel ausgeloggt! +
+ +
+ Du kannst dich nun [erneut einloggen] oder weiter auf unseren Seiten bleiben. ;-) +
diff --git a/inc/classes/main/commands/web/class_WebDoFormCommand.php b/inc/classes/main/commands/web/class_WebDoFormCommand.php index cdfd716..87bd1d1 100644 --- a/inc/classes/main/commands/web/class_WebDoFormCommand.php +++ b/inc/classes/main/commands/web/class_WebDoFormCommand.php @@ -1,6 +1,6 @@ * @version 0.0.0 diff --git a/inc/classes/main/commands/web/class_WebLoginAreaCommand.php b/inc/classes/main/commands/web/class_WebLoginAreaCommand.php index 9908233..ac26849 100644 --- a/inc/classes/main/commands/web/class_WebLoginAreaCommand.php +++ b/inc/classes/main/commands/web/class_WebLoginAreaCommand.php @@ -32,7 +32,7 @@ class WebLoginAreaCommand extends BaseCommand implements Commandable { parent::__construct(__CLASS__); // Set special description - $this->setObjectDescription("Command for the "home" page"); + $this->setObjectDescription("Command for the "login area" page"); // Create unique ID number $this->generateUniqueId(); @@ -128,13 +128,22 @@ class WebLoginAreaCommand extends BaseCommand implements Commandable { $templateInstance->loadCodeTemplate($action); // Assign the template with the master template as a content ... ;) - $templateInstance->assignTemplateWithVariable($action, "content"); + $templateInstance->assignTemplateWithVariable($action, "login_content"); + + // Load main template + $templateInstance->loadCodeTemplate("login_main"); + + // Assign the main template with the master template as a content ... ;) + $templateInstance->assignTemplateWithVariable("login_main", "content"); // Load the master template $templateInstance->loadCodeTemplate($masterTemplate); // Set title - $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage("login_{$action}_title")); + $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage($action."_title")); + + // Assign base URL + $templateInstance->assignConfigVariable('base_url'); // ... and all variables. This should be merged together in a pattern // to make things easier. A cache mechanism should be added between diff --git a/inc/classes/main/commands/web/class_WebLoginCommand.php b/inc/classes/main/commands/web/class_WebLoginCommand.php index 3f56321..64cba33 100644 --- a/inc/classes/main/commands/web/class_WebLoginCommand.php +++ b/inc/classes/main/commands/web/class_WebLoginCommand.php @@ -32,7 +32,7 @@ class WebLoginCommand extends BaseCommand implements Commandable { parent::__construct(__CLASS__); // Set special description - $this->setObjectDescription("Command for the "home" page"); + $this->setObjectDescription("Command for the login form page"); // Create unique ID number $this->generateUniqueId(); diff --git a/inc/classes/main/commands/web/class_WebLoginFailedCommand.php b/inc/classes/main/commands/web/class_WebLoginFailedCommand.php index 34a1970..04b02c1 100644 --- a/inc/classes/main/commands/web/class_WebLoginFailedCommand.php +++ b/inc/classes/main/commands/web/class_WebLoginFailedCommand.php @@ -32,7 +32,7 @@ class WebLoginFailedCommand extends BaseCommand implements Commandable { parent::__construct(__CLASS__); // Set special description - $this->setObjectDescription("Command for the "home" page"); + $this->setObjectDescription("Command for the "login failed" page"); // Create unique ID number $this->generateUniqueId(); @@ -101,6 +101,9 @@ class WebLoginFailedCommand extends BaseCommand implements Commandable { // Set title $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage('login_failed_title')); + // Assign base URL + $templateInstance->assignConfigVariable('base_url'); + // ... and all variables. This should be merged together in a pattern // to make things easier. A cache mechanism should be added between // these two calls to cache compiled templates. diff --git a/inc/classes/main/commands/web/class_WebLogoutDoneCommand.php b/inc/classes/main/commands/web/class_WebLogoutDoneCommand.php new file mode 100644 index 0000000..528f4b5 --- /dev/null +++ b/inc/classes/main/commands/web/class_WebLogoutDoneCommand.php @@ -0,0 +1,118 @@ + + * @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 WebLogoutDoneCommand extends BaseCommand implements Commandable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set special description + $this->setObjectDescription("Command for the "logout done" page"); + + // Create unique ID number + $this->generateUniqueId(); + + // Clean up a little + $this->removeSystemArray(); + } + + /** + * Creates an instance of this class + * + * @param $resolverInstance An instance of a command resolver class + * @return $commandInstance An instance a prepared command class + */ + public final static function createWebLogoutDoneCommand (CommandResolver $resolverInstance) { + // Get new instance + $commandInstance = new WebLogoutDoneCommand(); + + // Set the application instance + $commandInstance->setResolverInstance($resolverInstance); + + // Return the prepared instance + return $commandInstance; + } + + /** + * Executes the given 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 the application instance + $appInstance = $this->getResolverInstance()->getApplicationInstance(); + + // Prepare a template instance + $templateInstance = $this->prepareTemplateEngine($appInstance); + + // Load the master template + $masterTemplate = $appInstance->getMasterTemplate(); + + // Load header template + $templateInstance->loadCodeTemplate("header"); + + // Compile and assign it with a variable + $templateInstance->compileTemplate(); + $templateInstance->assignTemplateWithVariable("header", "header"); + + // Load footer template + $templateInstance->loadCodeTemplate("footer"); + + // Compile and assign it with a variable + $templateInstance->compileTemplate(); + $templateInstance->assignTemplateWithVariable("footer", "footer"); + + // Load the logout_done template + $templateInstance->loadCodeTemplate("logout_done"); + + // Assign the logout_done template with the master template as a content ... ;) + $templateInstance->assignTemplateWithVariable("logout_done", "content"); + + // Load the master template + $templateInstance->loadCodeTemplate($masterTemplate); + + // Set title + $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage('logout_done_title')); + + // Assign base URL + $templateInstance->assignConfigVariable('base_url'); + + // ... and all variables. This should be merged together in a pattern + // to make things easier. A cache mechanism should be added between + // these two calls to cache compiled templates. + $templateInstance->compileVariables(); + + // Get the content back from the template engine and put it in the response class + $templateInstance->transferToResponse($responseInstance); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/request/class_HttpRequest.php b/inc/classes/main/request/class_HttpRequest.php index b6f9b95..1a64747 100644 --- a/inc/classes/main/request/class_HttpRequest.php +++ b/inc/classes/main/request/class_HttpRequest.php @@ -86,13 +86,12 @@ class HttpRequest extends BaseFrameworkSystem implements Requestable { * Checks wether a request element is set * @param $element Name of the request element we want to check * @return $isSet Wether the request element is set - * @throws MissingArrayElementsException Thrown if a request element is not set */ public function isRequestElementSet ($element) { // Is this element found? if (!isset($this->requestData[$element])) { - // Then throw an exception - throw new MissingArrayElementsException(array($this, 'requestData', $element), self::EXCEPTION_MISSING_ELEMENT); + // Then return false + return false; } // END - if // All clear @@ -110,13 +109,9 @@ class HttpRequest extends BaseFrameworkSystem implements Requestable { // Initialize value $value = null; - try { - if ($this->isRequestElementSet($element)) { + if ($this->isRequestElementSet($element)) { $value = $this->requestData[$element]; - } // END - if - } catch (MissingArrayElementsException $e) { - // Do nothing here - } + } // END - if // Return the element's value return $value; diff --git a/inc/classes/main/resolver/web/class_WebCommandResolver.php b/inc/classes/main/resolver/web/class_WebCommandResolver.php index f4b87a2..ba0eb15 100644 --- a/inc/classes/main/resolver/web/class_WebCommandResolver.php +++ b/inc/classes/main/resolver/web/class_WebCommandResolver.php @@ -77,7 +77,7 @@ class WebCommandResolver extends BaseResolver implements CommandResolver { /** * Returns an command instance for a given request class or null if - * MissingArrayElementsException was thrown + * it was not found * * @param $requestInstance An instance of a request class * @return $commandInstance An instance of the resolved command @@ -91,34 +91,29 @@ class WebCommandResolver extends BaseResolver implements CommandResolver { $commandName = ""; $commandInstance = null; - // Test if the required parameter is set - try { - // This goes fine so let's resolv the command - $commandName = $requestInstance->getRequestElement("page"); + // 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'); + // 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); - } + // 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); + // 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); - } + // 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; - } catch (MissingArrayElementsException $e) { - // Just catch it here... - } + // Set last command + $this->lastCommandInstance = $commandInstance; // Return the resolved command instance return $commandInstance; diff --git a/inc/classes/main/resolver/web/class_WebControllerResolver.php b/inc/classes/main/resolver/web/class_WebControllerResolver.php index 6dd5a39..1debf14 100644 --- a/inc/classes/main/resolver/web/class_WebControllerResolver.php +++ b/inc/classes/main/resolver/web/class_WebControllerResolver.php @@ -95,31 +95,26 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { $commandName = ""; $controllerInstance = null; - // Try to resolv the command - try { - // 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); - } + // Get the command name + $commandName = $this->getCommandName(); - // Get the command - $controllerInstance = $this->loadController($commandName); + // 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 - // 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); - } + // Get the command + $controllerInstance = $this->loadController($commandName); - // Set last controller - $this->lastControllerInstance = $controllerInstance; - } catch (MissingArrayElementsException $e) { - // Just catch it here... - } + // 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); + } // END - if + + // Set last controller + $this->lastControllerInstance = $controllerInstance; // Return the maybe resolved instance return $controllerInstance; diff --git a/inc/classes/main/template/class_TemplateEngine.php b/inc/classes/main/template/class_TemplateEngine.php index 7378a40..7bbf2e1 100644 --- a/inc/classes/main/template/class_TemplateEngine.php +++ b/inc/classes/main/template/class_TemplateEngine.php @@ -319,17 +319,6 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate return $this->lastTemplate; } - /** - * Assign a given congfiguration variable with a value - * - * @param $var The configuration variable we want to assign - * @return void - */ - private final function assignConfigVariable ($var) { - // Sweet and simple... - $this->configVariables[$var] = $this->getConfigInstance()->readConfig($var); - } - /** * Initialize the variable stack. This holds all variables for later * compilation. @@ -511,7 +500,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate * @param $template The template we shall load * @return void */ - private final function loadTemplate ($template) { + private function loadTemplate ($template) { // Cast it to string $template = (string) $template; @@ -904,7 +893,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate * located in "html" by default * @return void */ - public final function loadWebTemplate ($template) { + public function loadWebTemplate ($template) { // Set template type $this->setTemplateType($this->getConfigInstance()->readConfig('web_template_type')); @@ -912,6 +901,17 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate $this->loadTemplate($template); } + /** + * Assign a given congfiguration variable with a value + * + * @param $var The configuration variable we want to assign + * @return void + */ + public function assignConfigVariable ($var) { + // Sweet and simple... + $this->configVariables[$var] = $this->getConfigInstance()->readConfig($var); + } + /** * Load a specified email template into the engine * @@ -919,7 +919,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate * located in "emails" by default * @return void */ - public final function loadEmailTemplate ($template) { + public function loadEmailTemplate ($template) { // Set template type $this->setTemplateType($this->getConfigInstance()->readConfig('email_template_type')); @@ -934,7 +934,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate * located in "code" by default * @return void */ - public final function loadCodeTemplate ($template) { + public function loadCodeTemplate ($template) { // Set template type $this->setTemplateType($this->getConfigInstance()->readConfig('code_template_type'));