From df494d7dff1401830f34852f8bbd74b8b2913dc2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 25 Jun 2008 11:00:10 +0000 Subject: [PATCH] Several fixes (new class/filters) for guest login --- .gitattributes | 3 + .../class_WebShipsimuGuestLoginCommand.php | 20 +-- .../web/class_WebShipsimuProfileCommand.php | 3 +- .../main/login/class_ShipSimuGuestLogin.php | 8 +- .../class_ShipSimuRegistration.php | 2 +- .../web/class_WebLogoutDoneController.php | 92 +++++++++++ .../main/filter/auth/class_UserAuthFilter.php | 2 +- .../guest/class_UserNameIsGuestFilter.php | 6 +- .../class_PasswordGuestVerifierFilter.php | 90 +++++++++++ .../class_UserGuestVerifierFilter.php | 148 ++++++++++++++++++ .../main/response/class_HttpResponse.php | 2 + inc/config.php | 8 +- inc/config/class_FrameworkConfiguration.php | 10 +- 13 files changed, 360 insertions(+), 34 deletions(-) create mode 100644 inc/classes/main/controller/web/class_WebLogoutDoneController.php create mode 100644 inc/classes/main/filter/verifier/class_PasswordGuestVerifierFilter.php create mode 100644 inc/classes/main/filter/verifier/class_UserGuestVerifierFilter.php diff --git a/.gitattributes b/.gitattributes index 74a28e0..5517841 100644 --- a/.gitattributes +++ b/.gitattributes @@ -412,6 +412,7 @@ inc/classes/main/controller/web/class_WebDefaultController.php -text inc/classes/main/controller/web/class_WebDefaultNewsController.php -text inc/classes/main/controller/web/class_WebLoginController.php -text inc/classes/main/controller/web/class_WebLoginFailedController.php -text +inc/classes/main/controller/web/class_WebLogoutDoneController.php -text inc/classes/main/controller/web/class_WebRegisterController.php -text inc/classes/main/criteria/.htaccess -text inc/classes/main/criteria/class_DataSetCriteria.php -text @@ -474,7 +475,9 @@ 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_PasswordGuestVerifierFilter.php -text inc/classes/main/filter/verifier/class_PasswordVerifierFilter.php -text +inc/classes/main/filter/verifier/class_UserGuestVerifierFilter.php -text inc/classes/main/filter/verifier/class_UserNameVerifierFilter.php -text inc/classes/main/filter/verifier/class_UserStatusVerifierFilter.php -text inc/classes/main/filter/verifier/class_UserUnconfirmedVerifierFilter.php -text diff --git a/application/ship-simu/main/commands/web/class_WebShipsimuGuestLoginCommand.php b/application/ship-simu/main/commands/web/class_WebShipsimuGuestLoginCommand.php index 9d747de..eedc22c 100644 --- a/application/ship-simu/main/commands/web/class_WebShipsimuGuestLoginCommand.php +++ b/application/ship-simu/main/commands/web/class_WebShipsimuGuestLoginCommand.php @@ -74,7 +74,7 @@ class WebShipsimuGuestLoginCommand extends BaseCommand implements Commandable { $loginInstance->setRequestInstance($requestInstance); // Encrypt the password - $loginInstance->encryptPassword('pass'); + $loginInstance->encryptPassword('passwd'); // Do the login here $loginInstance->doLogin($requestInstance, $responseInstance); @@ -103,23 +103,11 @@ class WebShipsimuGuestLoginCommand extends BaseCommand implements Commandable { * @todo Add more filters */ public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { - // Which login type do we have? - switch ($this->getConfigInstance()->readConfig('login_type')) { - case "username": // Login via username - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('username_verifier_class')); - break; - - case "email": // Login via email - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('email_verifier_class')); - break; - - default: // Wether username or email is set - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('username_email_verifier_class')); - break; - } + // Add username + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_guest_verifier_class')); // Add password verifier filter - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('password_verifier_class')); + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('passwd_guest_verifier_class')); } } diff --git a/application/ship-simu/main/commands/web/class_WebShipsimuProfileCommand.php b/application/ship-simu/main/commands/web/class_WebShipsimuProfileCommand.php index 107d093..5a0520f 100644 --- a/application/ship-simu/main/commands/web/class_WebShipsimuProfileCommand.php +++ b/application/ship-simu/main/commands/web/class_WebShipsimuProfileCommand.php @@ -113,7 +113,8 @@ class WebShipsimuProfileCommand extends BaseCommand implements Commandable { unset($this->allowedData); // Unfinished! - $this->debugInstance(); + $this->partialStub("Unfinished work."); + $this->debugBackTrace(); } /** diff --git a/application/ship-simu/main/login/class_ShipSimuGuestLogin.php b/application/ship-simu/main/login/class_ShipSimuGuestLogin.php index 4fe5915..47af7cd 100644 --- a/application/ship-simu/main/login/class_ShipSimuGuestLogin.php +++ b/application/ship-simu/main/login/class_ShipSimuGuestLogin.php @@ -81,14 +81,10 @@ class ShipSimuGuestLogin extends BaseFrameworkSystem implements LoginableUser { $data = ""; // Detect login method (username or email) and try to get a userinstance - if (!is_null($requestInstance->getRequestElement('username'))) { + if (!is_null($requestInstance->getRequestElement('user'))) { // Username found! $method = "createGuestByUsername"; - $data = $requestInstance->getRequestElement('username'); - } elseif (!is_null($requestInstance->getRequestElement('email'))) { - // Email found! - $method = "createGuestByEmail"; - $data = $requestInstance->getRequestElement('email'); + $data = $requestInstance->getRequestElement('user'); } // Is a method detected? diff --git a/application/ship-simu/main/registration/class_ShipSimuRegistration.php b/application/ship-simu/main/registration/class_ShipSimuRegistration.php index 87a4429..f625eac 100644 --- a/application/ship-simu/main/registration/class_ShipSimuRegistration.php +++ b/application/ship-simu/main/registration/class_ShipSimuRegistration.php @@ -174,7 +174,7 @@ class ShipSimuRegistration extends BaseRegistration { } // Is this a guest account? - if ((($element == "username") || ($alias == "username")) && ($this->getRequestInstance()->getRequestElement($element) == $this->getConfigInstance()->readConfig('guest_login_username'))) { + if ((($element == "username") || ($alias == "username")) && ($this->getRequestInstance()->getRequestElement($element) == $this->getConfigInstance()->readConfig('guest_login_user'))) { // Yes, then set the config entry to guest status $configEntry = 'user_status_guest'; } // END - if diff --git a/inc/classes/main/controller/web/class_WebLogoutDoneController.php b/inc/classes/main/controller/web/class_WebLogoutDoneController.php new file mode 100644 index 0000000..dce9fab --- /dev/null +++ b/inc/classes/main/controller/web/class_WebLogoutDoneController.php @@ -0,0 +1,92 @@ + + * @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 WebLogoutDoneController extends BaseController implements Controller { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("Controller for login form"); + + // Create unique ID number + $this->generateUniqueId(); + } + + /** + * 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 createWebLogoutDoneController (CommandResolver $resolverInstance) { + // Create the instance + $controllerInstance = new WebLogoutDoneController(); + + // Set the command resolver + $controllerInstance->setResolverInstance($resolverInstance); + + + // 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); + + // Run the pre filters + $this->executePreFilters($requestInstance, $responseInstance); + + // 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/inc/classes/main/filter/auth/class_UserAuthFilter.php b/inc/classes/main/filter/auth/class_UserAuthFilter.php index c346615..db698c2 100644 --- a/inc/classes/main/filter/auth/class_UserAuthFilter.php +++ b/inc/classes/main/filter/auth/class_UserAuthFilter.php @@ -107,7 +107,7 @@ class UserAuthFilter extends BaseFilter implements Filterable { } // END - if // Now, try to get a user or guest instance - if ($authLogin == $this->getConfigInstance()->readConfig('guest_login_username')) { + if ($authLogin == $this->getConfigInstance()->readConfig('guest_login_user')) { // Guest login! $userInstance = Guest::createGuestByUserName($authLogin); } else { diff --git a/inc/classes/main/filter/guest/class_UserNameIsGuestFilter.php b/inc/classes/main/filter/guest/class_UserNameIsGuestFilter.php index b32f0cc..34def47 100644 --- a/inc/classes/main/filter/guest/class_UserNameIsGuestFilter.php +++ b/inc/classes/main/filter/guest/class_UserNameIsGuestFilter.php @@ -64,10 +64,10 @@ class UserNameIsGuestFilter extends BaseFilter implements Filterable { $userName = $requestInstance->getRequestElement('username'); // Does the user name match the guest login? - if ($userName == $this->getConfigInstance()->readConfig('guest_login_username')) { + if ($userName == $this->getConfigInstance()->readConfig('guest_login_user')) { // Then set the password to the configured password - $requestInstance->setRequestElement('pass1', $this->getConfigInstance()->readConfig('guest_login_password')); - $requestInstance->setRequestElement('pass2', $this->getConfigInstance()->readConfig('guest_login_password')); + $requestInstance->setRequestElement('pass1', $this->getConfigInstance()->readConfig('guest_login_passwd')); + $requestInstance->setRequestElement('pass2', $this->getConfigInstance()->readConfig('guest_login_passwd')); } // END - if } } diff --git a/inc/classes/main/filter/verifier/class_PasswordGuestVerifierFilter.php b/inc/classes/main/filter/verifier/class_PasswordGuestVerifierFilter.php new file mode 100644 index 0000000..7e47214 --- /dev/null +++ b/inc/classes/main/filter/verifier/class_PasswordGuestVerifierFilter.php @@ -0,0 +1,90 @@ + + * @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 PasswordGuestVerifierFilter 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 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 createPasswordGuestVerifierFilter () { + // Get a new instance + $filterInstance = new PasswordGuestVerifierFilter(); + + // 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 password + $password = $requestInstance->getRequestElement('passwd'); + + // 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('password_unset'); + + // Abort here + return false; + } elseif (empty($password)) { + // Password is empty + $requestInstance->requestIsValid(false); + + // Add a message to the response + $responseInstance->addFatalMessage('password_empty'); + + // Abort here + return false; + } + } +} + +// [EOF] +?> diff --git a/inc/classes/main/filter/verifier/class_UserGuestVerifierFilter.php b/inc/classes/main/filter/verifier/class_UserGuestVerifierFilter.php new file mode 100644 index 0000000..957407a --- /dev/null +++ b/inc/classes/main/filter/verifier/class_UserGuestVerifierFilter.php @@ -0,0 +1,148 @@ + + * @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 UserGuestVerifierFilter 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 username 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 createUserGuestVerifierFilter () { + // Get a new instance + $filterInstance = new UserGuestVerifierFilter(); + + // 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 username from request + $userName = $requestInstance->getRequestElement('user'); + + // Is the username set? + if (is_null($userName)) { + // Not found in form so stop the filtering process + $requestInstance->requestIsValid(false); + + // Add a message to the response + $responseInstance->addFatalMessage('username_unset'); + + // Abort here + return false; + } elseif (empty($userName)) { + // Empty field! + $requestInstance->requestIsValid(false); + + // Add a message to the response + $responseInstance->addFatalMessage('username_empty'); + + // Abort here + return false; + } elseif (!$this->ifUserGuestIsTaken($userName)) { + // Username is already taken + $requestInstance->requestIsValid(false); + + // Add a message to the response + $responseInstance->addFatalMessage('username_not_found'); + + // Abort here + return false; + } + + // Set the element for compatiblity reasons + $requestInstance->setRequestElement('username', $userName); + } + + /** + * Check wether the username as already been taken + * + * @param $userName Username to check for existence + * @return $alreadyTaken Wether the username has been taken + */ + private function ifUserGuestIsTaken ($userName) { + // Default is already taken + $alreadyTaken = true; + + // Initialize instance + $userInstance = null; + + // Get a registry instance + $registry = Registry::getRegistry(); + + // Is the user already there? + if ($registry->instanceExists('user')) { + // Use the instance for checking for the email + $userInstance = $registry->getInstance('user'); + $userInstance->setUserGuest($userName); + } else { + // If this instance is created then the username *does* exist + try { + // Get a new instance + $userInstance = call_user_func_array(array($this->getConfigInstance()->readConfig('guest_class'), "createGuestByUsername"), array($userName)); + + // Remember this user instance in our registry for later usage + $registry->addInstance('user', $userInstance); + } catch (UsernameMissingException $e) { + // User was not found + } + } + + // Does the username exist? + if ((is_null($userInstance)) || (!$userInstance->ifUsernameExists())) { + // This username is still available + $alreadyTaken = false; + } + + // Return the result + return $alreadyTaken; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/response/class_HttpResponse.php b/inc/classes/main/response/class_HttpResponse.php index d318969..bcdf492 100644 --- a/inc/classes/main/response/class_HttpResponse.php +++ b/inc/classes/main/response/class_HttpResponse.php @@ -252,9 +252,11 @@ class HttpResponse extends BaseFrameworkSystem implements Responseable { * @todo this will send only one cookie out, the first one. */ public function addCookie ($cookieName, $cookieValue, $encrypted = false, $expires = null) { + //* DEBUG: */ echo $cookieName."=".$cookieValue."
\n"; // Are headers already sent? if (headers_sent()) { // Throw an exception here + //* DEBUG: */ return; throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT); } // END - if diff --git a/inc/config.php b/inc/config.php index a23d685..03afd0a 100644 --- a/inc/config.php +++ b/inc/config.php @@ -188,15 +188,21 @@ $cfg->setConfigEntry('password_validator_class', "PasswordValidatorFilter"); // CFG: RULES-ACCEPTED-CLASS $cfg->setConfigEntry('rules_accepted_class', "RulesAcceptedFilter"); -// CFG: USERNAME-VERIFIER +// CFG: USERNAME-VERIFIER-CLASS $cfg->setConfigEntry('username_verifier_class', "UserNameVerifierFilter"); +// CFG: USER-GUEST-VERIFIER-CLASS +$cfg->setConfigEntry('user_guest_verifier_class', "UserGuestVerifierFilter"); + // CFG: EMAIL-VERIFIER $cfg->setConfigEntry('email_verifier_class', "EmailVerifierFilter"); // CFG: PASSWORD-VERIFIER-CLASS $cfg->setConfigEntry('password_verifier_class', "PasswordVerifierFilter"); +// CFG: PASSWD-GUEST-VERIFIER-CLASS +$cfg->setConfigEntry('passwd_guest_verifier_class', "PasswordGuestVerifierFilter"); + // CFG: EMAIL-CHANGE-CLASS $cfg->setConfigEntry('email_change_class', "EmailChangeFilter"); diff --git a/inc/config/class_FrameworkConfiguration.php b/inc/config/class_FrameworkConfiguration.php index 6d3b99f..e6d3380 100644 --- a/inc/config/class_FrameworkConfiguration.php +++ b/inc/config/class_FrameworkConfiguration.php @@ -104,7 +104,7 @@ class FrameworkConfiguration implements Registerable { // At least 5.1.0 is required for this! if (version_compare(phpversion(), "5.1.0")) { @date_default_timezone_set($zone); - } + } // END - if } /** @@ -141,12 +141,12 @@ class FrameworkConfiguration implements Registerable { // Base path is already added $fqfn = $inc; } - } + } // END - if // Include them all here require($fqfn); } - } + } // END - if } /** @@ -226,7 +226,7 @@ class FrameworkConfiguration implements Registerable { // Debug message if ((defined('DEBUG_CONFIG')) || (defined('DEBUG_ALL'))) { echo "[".__METHOD__."] Configuration entry ".$cfgEntry." requested.
\n"; - } + } // END - if // Return the requested value return $this->config[$cfgEntry]; @@ -249,7 +249,7 @@ class FrameworkConfiguration implements Registerable { if (empty($cfgEntry)) { // Entry is empty throw new ConfigEntryIsEmptyException($this, self::EXCEPTION_CONFIG_ENTRY_IS_EMPTY); - } + } // END - if // Set the configuration value $this->config[$cfgEntry] = $cfgValue; -- 2.39.5