From fd80d47afc96ae0c0759530800051a0f07eb9c92 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 12 Jun 2008 22:51:28 +0000 Subject: [PATCH] Results are now searchable and iterateable, insertDataSet renamed to queryInsertDataSet, login added with stubs --- .gitattributes | 8 ++ application/selector/loader.php | 9 +- application/ship-simu/config.php | 3 + application/ship-simu/loader.php | 9 +- .../main/login/class_ShipSimuUserLogin.php | 24 +++-- .../ship-simu/main/login/helper/.htaccess | 1 + .../helper/class_ShipSimuLoginHelper.php | 98 +++++++++++++++++++ .../class_UserInstanceMissingException.php | 46 +++++++++ .../class_UserPasswordMismatchException.php | 46 +++++++++ .../interfaces/cache/class_Cacheable.php | 2 +- inc/classes/interfaces/class_ | 2 +- .../interfaces/criteria/class_Criteria.php | 2 +- .../extended/class_LocalSearchCriteria.php | 4 +- .../class_DatabaseFrontendInterface.php | 4 +- .../interfaces/login/class_LoginableUser.php | 2 +- .../registration/class_UserRegister.php | 2 +- .../interfaces/registry/class_Register.php | 2 +- .../registry/class_Registerable.php | 2 +- inc/classes/interfaces/result/.htaccess | 1 + .../result/class_SearchableResult.php | 35 +++++++ .../interfaces/user/class_ManageableUser.php | 31 ++++++ inc/classes/main/actions/class_BaseAction.php | 4 +- inc/classes/main/cache/class_MemoryCache.php | 4 +- .../main/class_BaseFrameworkSystem.php | 12 +-- inc/classes/main/commands/class_ | 2 +- .../main/criteria/class_SearchCriteria.php | 4 +- .../main/crypto/class_CryptoHelper.php | 4 +- .../databases/class_LocalFileDatabase.php | 10 +- .../wrapper/class_UserDatabaseWrapper.php | 2 +- .../main/debug/class_DebugConsoleOutput.php | 2 +- inc/classes/main/helper/login/.htaccess | 1 + .../helper/login/class_BaseLoginHelper.php | 38 +++++++ .../registration/class_BaseRegistration.php | 4 +- inc/classes/main/registry/class_Registry.php | 4 +- .../main/result/class_DatabaseResult.php | 91 ++++++++++++++++- .../main/rng/class_RandomNumberGenerator.php | 4 +- inc/classes/main/user/class_User.php | 69 +++++++++++-- .../database/class_DatabaseConnection.php | 4 +- 38 files changed, 514 insertions(+), 78 deletions(-) create mode 100644 application/ship-simu/main/login/helper/.htaccess create mode 100644 application/ship-simu/main/login/helper/class_ShipSimuLoginHelper.php create mode 100644 inc/classes/exceptions/helper/class_UserInstanceMissingException.php create mode 100644 inc/classes/exceptions/user/class_UserPasswordMismatchException.php create mode 100644 inc/classes/interfaces/result/.htaccess create mode 100644 inc/classes/interfaces/result/class_SearchableResult.php create mode 100644 inc/classes/main/helper/login/.htaccess create mode 100644 inc/classes/main/helper/login/class_BaseLoginHelper.php diff --git a/.gitattributes b/.gitattributes index 343d112..e2ffaca 100644 --- a/.gitattributes +++ b/.gitattributes @@ -84,6 +84,8 @@ application/ship-simu/main/factories/.htaccess -text application/ship-simu/main/factories/class_ShipSimuWebNewsFactory.php -text application/ship-simu/main/login/.htaccess -text application/ship-simu/main/login/class_ShipSimuUserLogin.php -text +application/ship-simu/main/login/helper/.htaccess -text +application/ship-simu/main/login/helper/class_ShipSimuLoginHelper.php -text application/ship-simu/main/parts/.htaccess -text application/ship-simu/main/parts/class_BaseShipPart.php -text application/ship-simu/main/parts/maschineroom/.htaccess -text @@ -173,6 +175,7 @@ inc/classes/exceptions/helper/class_FormClosedException.php -text inc/classes/exceptions/helper/class_FormGroupClosedException.php -text inc/classes/exceptions/helper/class_FormOpenedException.php -text inc/classes/exceptions/helper/class_InvalidFormNameException.php -text +inc/classes/exceptions/helper/class_UserInstanceMissingException.php -text inc/classes/exceptions/io/.htaccess -text inc/classes/exceptions/io/class_DirPointerNotOpenedException.php -text inc/classes/exceptions/io/class_FilePointerNotOpenedException.php -text @@ -224,6 +227,7 @@ inc/classes/exceptions/template/class_UnsupportedTemplateEngineException.php -te inc/classes/exceptions/template/class_ViewHelperNotFoundException.php -text inc/classes/exceptions/user/.htaccess -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/application/.htaccess -text @@ -278,6 +282,8 @@ inc/classes/interfaces/resolver/class_CommandResolver.php -text inc/classes/interfaces/resolver/class_ControllerResolver.php -text inc/classes/interfaces/response/.htaccess -text inc/classes/interfaces/response/class_Responseable.php -text +inc/classes/interfaces/result/.htaccess -text +inc/classes/interfaces/result/class_SearchableResult.php -text inc/classes/interfaces/template/.htaccess -text inc/classes/interfaces/template/class_CompileableTemplate.php -text inc/classes/interfaces/template/view/class_ViewHelper.php -text @@ -359,6 +365,8 @@ inc/classes/main/filter/validator/class_UserNameValidatorFilter.php -text inc/classes/main/helper/.htaccess -text inc/classes/main/helper/class_ -text inc/classes/main/helper/class_BaseHelper.php -text +inc/classes/main/helper/login/.htaccess -text +inc/classes/main/helper/login/class_BaseLoginHelper.php -text inc/classes/main/helper/web/.htaccess -text inc/classes/main/helper/web/class_WebFormHelper.php -text inc/classes/main/io/.htaccess -text diff --git a/application/selector/loader.php b/application/selector/loader.php index ace39f5..9869069 100644 --- a/application/selector/loader.php +++ b/application/selector/loader.php @@ -21,14 +21,11 @@ * along with this program. If not, see . */ -// Is the application instance set? -if (!isset($application)) { - // We need this! - ApplicationEntryPoint::app_die("[Main:] Interne Variable application nicht gefunden!"); -} +// Get config instance +$cfg = FrameworkConfiguration::getInstance(); // Load all classes -ClassLoader::getInstance()->loadClasses(sprintf("%s/%s/", FrameworkConfiguration::getInstance()->readConfig('application_path'), $application)); +ClassLoader::getInstance()->loadClasses(sprintf("%s/%s/", $cfg->readConfig('application_path'), $cfg->readConfig('app_name'))); // Clean up the global namespace unset($lowerClasses); diff --git a/application/ship-simu/config.php b/application/ship-simu/config.php index 2d5cd1f..87c01c4 100644 --- a/application/ship-simu/config.php +++ b/application/ship-simu/config.php @@ -79,5 +79,8 @@ $cfg->setConfigEntry('login_user', "ShipSimuUserLogin"); // CFG: USER-STATUS-REGISTER $cfg->setConfigEntry('user_status_register', "UNCONFIRMED"); +// CFG: LOGIN-HELPER +$cfg->setConfigEntry('login_helper', "ShipSimuLoginHelper"); + // [EOF] ?> diff --git a/application/ship-simu/loader.php b/application/ship-simu/loader.php index 0ffd93f..d60af4c 100644 --- a/application/ship-simu/loader.php +++ b/application/ship-simu/loader.php @@ -22,17 +22,14 @@ * along with this program. If not, see . */ -// Is the application instance set? -if (!isset($application)) { - // We need this! - ApplicationEntryPoint::app_die("[Main:] Interne Variable application nicht gefunden!"); -} +// Get config instance +$cfg = FrameworkConfiguration::getInstance(); // Load all classes for the application foreach ($lowerClasses as $class) { // Try to load the application classes try { - ClassLoader::getInstance()->loadClasses(sprintf("%s/%s/%s", FrameworkConfiguration::getInstance()->readConfig('application_path'), $application, $class)); + ClassLoader::getInstance()->loadClasses(sprintf("%s/%s/%s", $cfg->readConfig('application_path'), $cfg->readConfig('app_name'), $class)); } catch (PathIsNoDirectoryException $e) { ApplicationEntryPoint::app_die(sprintf("[Main:%s] Cannot find application classes in path %s for this reason: %s", $application, diff --git a/application/ship-simu/main/login/class_ShipSimuUserLogin.php b/application/ship-simu/main/login/class_ShipSimuUserLogin.php index 7caea51..a043de8 100644 --- a/application/ship-simu/main/login/class_ShipSimuUserLogin.php +++ b/application/ship-simu/main/login/class_ShipSimuUserLogin.php @@ -66,8 +66,8 @@ class ShipSimuUserLogin extends BaseFrameworkSystem implements LoginableUser { * was detected * @throws MissingMethodException If a method was not found in the * User class - * @throws UserEmailMissingException If user with given email address was - * not found in database + * @throws UserPasswordMismatchException If the supplied password did not + * match with the stored password */ public function doLogin (Requestable $requestInstance) { // By default no method is selected @@ -101,16 +101,24 @@ class ShipSimuUserLogin extends BaseFrameworkSystem implements LoginableUser { if (is_null($userInstance)) { // Get a user instance $userInstance = call_user_func_array(array($this->getConfigInstance()->readConfig('user_class'), $method), array($data)); + + // Remember this new instance in registry + Registry::getRegistry()->addInstance($userInstance); } // END - if - // If we have email login then check if a user account with that email exists! - if (($method == "createUserByEmail") && (!$userInstance->ifEmailAddressExists())) { - // The user account is missing! - throw new UserEmailMissingException(array($this, $data), User::EXCEPTION_USER_EMAIL_NOT_FOUND); + // Is the password correct? + if (!$userInstance->ifPasswordHashMatches($requestInstance)) { + // Mismatching password + throw new UserPasswordMismatchException(array($this, $userInstance), User::EXCEPTION_USER_PASS_MISMATCH); } // END - if - // Partially finished! - $this->partialStub("userInstance set, continue with password verification"); + // Now do the real login. This can be cookie- or session-based login + // which depends on the admins setting then on the user's taste. + // 1) Get a login helper instance + $helperInstance = ObjectFactory::createObjectByConfiguredName('login_helper', array($requestInstance)); + + // 2) Execute the login. This will now login... + $helperInstance->executeLogin(); } } diff --git a/application/ship-simu/main/login/helper/.htaccess b/application/ship-simu/main/login/helper/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/ship-simu/main/login/helper/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/ship-simu/main/login/helper/class_ShipSimuLoginHelper.php b/application/ship-simu/main/login/helper/class_ShipSimuLoginHelper.php new file mode 100644 index 0000000..13bed29 --- /dev/null +++ b/application/ship-simu/main/login/helper/class_ShipSimuLoginHelper.php @@ -0,0 +1,98 @@ + + * @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 + * @todo Find an interface name for login helper + * + * 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 ShipSimuLoginHelper extends BaseLoginHelper { + // Exception constants + const EXCEPTION_INVALID_USER_INSTANCE = 0xf00; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("Login helper for Ship-Simu"); + + // Create unique ID number + $this->generateUniqueId(); + } + + /** + * Creates an instance of this class by given request instance + * + * @param $requestInstance An instance of a Requestable class + * @return $helperInstance An instance of this helper class + * @throws UserInstanceMissingException If the user instance in registry + * is missing or invalid + */ + public final static function createShipSimuLoginHelper (Requestable $requestInstance) { + // Get a new instance first + $helperInstance = new ShipSimuLoginHelper(); + + // Get a user instance from registry + $userInstance = Registry::getRegistry()->getInstance('user'); + + // Is this instance valid? + if (!$userInstance instanceof ManageableUser) { + // Thrown an exception here + throw new UserInstanceMissingException (array($helperInstance, 'user'), self::EXCEPTION_INVALID_USER_INSTANCE); + } // END - if + + // Get the login method from request + $methodRequest = $requestInstance->getRequestElement('login_method'); + + // Now, if that wents fine we can check if the request includes a login method entry + if ((!is_null($methodRequest)) && ($methodRequest != "default") && ($methodRequest != $userInstance->getLoginMethod())) { + // Okay, the login method has been choosen by user so remember it + $helperInstance->setLoginMethod($methodRequest); + + // Remeber that we need to update the user account as well + $userInstance->addUpdateData('login_method', $methodRequest); + } elseif (($methodRequest == "default") && (is_string($userInstance->getLoginMethod()))) { + // Choose default method from user + $helperInstance->setLoginMethod($userInstance->getLoginMethod()); + } else { + // Set default login method from config + $helperInstance->setDefaultLoginMethod(); + } + + // Return the prepared instance + return $helperInstance; + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/helper/class_UserInstanceMissingException.php b/inc/classes/exceptions/helper/class_UserInstanceMissingException.php new file mode 100644 index 0000000..ecdf3c7 --- /dev/null +++ b/inc/classes/exceptions/helper/class_UserInstanceMissingException.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 UserInstanceMissingException extends FrameworkException { + /** + * The constructor + * + * @param $classArray Array with class instance and registry key + * @param $code Code number for the exception + * @return void + */ + public function __construct (array $classArray, $code) { + // Add a message around the missing class + $message = sprintf("[%s:%d] Registry key %s does not include a class with implemented interface ManageableUser.", + $classArray[0]->__toString(), + $this->getLine(), + $classArray[1] + ); + + // Call parent constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/user/class_UserPasswordMismatchException.php b/inc/classes/exceptions/user/class_UserPasswordMismatchException.php new file mode 100644 index 0000000..032437c --- /dev/null +++ b/inc/classes/exceptions/user/class_UserPasswordMismatchException.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 UserPasswordMismatchException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $msgArray The non-optional message for the exception + * @param $code An optional code for better debugging + * @return void + */ + public function __construct(array $msgArray, $code = 0) { + // Create the message + $message = sprintf("[%s:%d] Supplied password for user %s did not match with stored password.", + $msgArray[0]->__toString(), + $this->getLine(), + $msgArray[1]->getUserName() + ); + + // Make sure everything is assigned properly + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/interfaces/cache/class_Cacheable.php b/inc/classes/interfaces/cache/class_Cacheable.php index c6fa237..23e4f0f 100644 --- a/inc/classes/interfaces/cache/class_Cacheable.php +++ b/inc/classes/interfaces/cache/class_Cacheable.php @@ -2,7 +2,7 @@ /** * An interface for classes which are "able" to cache * - * @author Roland Haeder + * @author Roland Haeder * @version 0.0.0 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version diff --git a/inc/classes/interfaces/class_ b/inc/classes/interfaces/class_ index 055ad90..264d3d9 100644 --- a/inc/classes/interfaces/class_ +++ b/inc/classes/interfaces/class_ @@ -2,7 +2,7 @@ /** * * - * @author Roland Haeder + * @author Roland Haeder * @version 0.0.0 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version diff --git a/inc/classes/interfaces/criteria/class_Criteria.php b/inc/classes/interfaces/criteria/class_Criteria.php index 35b51f3..b4bfec6 100644 --- a/inc/classes/interfaces/criteria/class_Criteria.php +++ b/inc/classes/interfaces/criteria/class_Criteria.php @@ -2,7 +2,7 @@ /** * An interface for criterias * - * @author Roland Haeder + * @author Roland Haeder * @version 0.0.0 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version diff --git a/inc/classes/interfaces/criteria/extended/class_LocalSearchCriteria.php b/inc/classes/interfaces/criteria/extended/class_LocalSearchCriteria.php index 2ac9efd..785c3c6 100644 --- a/inc/classes/interfaces/criteria/extended/class_LocalSearchCriteria.php +++ b/inc/classes/interfaces/criteria/extended/class_LocalSearchCriteria.php @@ -2,7 +2,7 @@ /** * An interface for local criterias * - * @author Roland Haeder + * @author Roland Haeder * @version 0.0.0 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -interface LocalCriteria extends Criteria { +interface LocalSearchCriteria extends Criteria { } // diff --git a/inc/classes/interfaces/database/frontend/class_DatabaseFrontendInterface.php b/inc/classes/interfaces/database/frontend/class_DatabaseFrontendInterface.php index f61df07..0bdf820 100644 --- a/inc/classes/interfaces/database/frontend/class_DatabaseFrontendInterface.php +++ b/inc/classes/interfaces/database/frontend/class_DatabaseFrontendInterface.php @@ -56,7 +56,7 @@ interface DatabaseFrontendInterface extends FrameworkDatabaseInterface { * @throws UnsupportedCriteriaException If the criteria is unsupported * @throws SqlException If an SQL error occurs */ - function querySelect ($resultType, $tableName, Criteria $criteriaInstance); + function querySelect ($resultType, $tableName, LocalSearchCriteria $criteriaInstance); /** * "Inserts" a data set instance into a local file database folder @@ -65,7 +65,7 @@ interface DatabaseFrontendInterface extends FrameworkDatabaseInterface { * @return void * @throws SqlException If an SQL error occurs */ - function insertDataSet (StoreableCriteria $dataSetInstance); + function queryInsertDataSet (StoreableCriteria $dataSetInstance); } // [EOF] diff --git a/inc/classes/interfaces/login/class_LoginableUser.php b/inc/classes/interfaces/login/class_LoginableUser.php index c7abf2d..c9a842a 100644 --- a/inc/classes/interfaces/login/class_LoginableUser.php +++ b/inc/classes/interfaces/login/class_LoginableUser.php @@ -2,7 +2,7 @@ /** * An interface for user login classes * - * @author Roland Haeder + * @author Roland Haeder * @version 0.0.0 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version diff --git a/inc/classes/interfaces/registration/class_UserRegister.php b/inc/classes/interfaces/registration/class_UserRegister.php index 9fbf2ff..3f04623 100644 --- a/inc/classes/interfaces/registration/class_UserRegister.php +++ b/inc/classes/interfaces/registration/class_UserRegister.php @@ -2,7 +2,7 @@ /** * A class for user registration * - * @author Roland Haeder + * @author Roland Haeder * @version 0.0.0 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version diff --git a/inc/classes/interfaces/registry/class_Register.php b/inc/classes/interfaces/registry/class_Register.php index a750ac1..083679f 100644 --- a/inc/classes/interfaces/registry/class_Register.php +++ b/inc/classes/interfaces/registry/class_Register.php @@ -2,7 +2,7 @@ /** * An interface for registries * - * @author Roland Haeder + * @author Roland Haeder * @version 0.0.0 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version diff --git a/inc/classes/interfaces/registry/class_Registerable.php b/inc/classes/interfaces/registry/class_Registerable.php index 0616d00..5a9105e 100644 --- a/inc/classes/interfaces/registry/class_Registerable.php +++ b/inc/classes/interfaces/registry/class_Registerable.php @@ -2,7 +2,7 @@ /** * A class for registerable classes * - * @author Roland Haeder + * @author Roland Haeder * @version 0.0.0 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version diff --git a/inc/classes/interfaces/result/.htaccess b/inc/classes/interfaces/result/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/interfaces/result/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/interfaces/result/class_SearchableResult.php b/inc/classes/interfaces/result/class_SearchableResult.php new file mode 100644 index 0000000..5afb8f8 --- /dev/null +++ b/inc/classes/interfaces/result/class_SearchableResult.php @@ -0,0 +1,35 @@ + + * @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 SearchableResult extends FrameworkInterface { + /** + * Searches for an entry in the data result and returns it + * + * @param $criteriaInstance The criteria to look inside the data set + * @return $result Found result entry + */ + function searchEntry (LocalSearchCriteria $criteriaInstance); +} + +// [EOF] +?> diff --git a/inc/classes/interfaces/user/class_ManageableUser.php b/inc/classes/interfaces/user/class_ManageableUser.php index 768df47..40c4b73 100644 --- a/inc/classes/interfaces/user/class_ManageableUser.php +++ b/inc/classes/interfaces/user/class_ManageableUser.php @@ -22,6 +22,37 @@ * along with this program. If not, see . */ interface ManageableUser extends FrameworkInterface { + /** + * Determines wether the username exists or not + * + * @return $exists Wether the username exists + */ + function ifUsernameExists (); + + /** + * Determines wether the email exists or not + * + * @return $exists Wether the email exists + */ + function ifEmailAddressExists (); + + /** + * Checks if the supplied password hash in request matches with the stored + * in database. + * + * @param $requestInstance A requestable class instance + * @return $matches Wether the supplied password hash matches + */ + function ifPasswordHashMatches (Requestable $requestInstance); + + /** + * Adds data for later complete update + * + * @param $column Column we want to update + * @param $value New value to store in database + * @return void + */ + function addUpdateData ($column, $value); } // diff --git a/inc/classes/main/actions/class_BaseAction.php b/inc/classes/main/actions/class_BaseAction.php index 9b2df36..15ba51e 100644 --- a/inc/classes/main/actions/class_BaseAction.php +++ b/inc/classes/main/actions/class_BaseAction.php @@ -3,10 +3,10 @@ * A general action class * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 diff --git a/inc/classes/main/cache/class_MemoryCache.php b/inc/classes/main/cache/class_MemoryCache.php index 01d2a36..4cb7459 100644 --- a/inc/classes/main/cache/class_MemoryCache.php +++ b/inc/classes/main/cache/class_MemoryCache.php @@ -3,10 +3,10 @@ * A simple memory cache (similar to a registry) * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index 2a0c807..d8d095f 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -61,7 +61,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { /** * The file I/O instance for the template loader */ - private $fileIOInstance = null; + private $fileIoInstance = null; /*********************** * Exception codes.... * @@ -758,20 +758,20 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { /** * Private getter for file IO instance * - * @return $fileIOInstance An instance to the file I/O sub-system + * @return $fileIoInstance An instance to the file I/O sub-system */ protected final function getFileIoInstance () { - return $this->fileIOInstance; + return $this->fileIoInstance; } /** * Setter for file I/O instance * - * @param $fileIOInstance An instance to the file I/O sub-system + * @param $fileIoInstance An instance to the file I/O sub-system * @return void */ - public final function setFileIoInstance (FileIoHandler $fileIOInstance) { - $this->fileIOInstance = $fileIOInstance; + public final function setFileIoInstance (FileIoHandler $fileIoInstance) { + $this->fileIoInstance = $fileIoInstance; } /** diff --git a/inc/classes/main/commands/class_ b/inc/classes/main/commands/class_ index 628cd0f..df55736 100644 --- a/inc/classes/main/commands/class_ +++ b/inc/classes/main/commands/class_ @@ -2,7 +2,7 @@ /** * * - * @author Roland Haeder + * @author Roland Haeder * @version 0.0.0 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software * @license GNU GPL 3.0 or any newer version diff --git a/inc/classes/main/criteria/class_SearchCriteria.php b/inc/classes/main/criteria/class_SearchCriteria.php index f948909..fc5b1ad 100644 --- a/inc/classes/main/criteria/class_SearchCriteria.php +++ b/inc/classes/main/criteria/class_SearchCriteria.php @@ -5,10 +5,10 @@ * for looking in storages like the database. * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 diff --git a/inc/classes/main/crypto/class_CryptoHelper.php b/inc/classes/main/crypto/class_CryptoHelper.php index cdde421..4ec02ad 100644 --- a/inc/classes/main/crypto/class_CryptoHelper.php +++ b/inc/classes/main/crypto/class_CryptoHelper.php @@ -3,10 +3,10 @@ * A helper class for cryptographical things like hashing passwords and so on * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 diff --git a/inc/classes/main/database/databases/class_LocalFileDatabase.php b/inc/classes/main/database/databases/class_LocalFileDatabase.php index 151698c..bf19a67 100644 --- a/inc/classes/main/database/databases/class_LocalFileDatabase.php +++ b/inc/classes/main/database/databases/class_LocalFileDatabase.php @@ -535,16 +535,10 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend * @throws UnsupportedCriteriaException If the criteria is unsupported * @throws SqlException If an "SQL error" occurs */ - public function querySelect ($resultType, $tableName, Criteria $criteriaInstance) { + public function querySelect ($resultType, $tableName, LocalSearchCriteria $criteriaInstance) { // The result is null by any errors $resultData = null; - // Is this criteria supported? - if (!$criteriaInstance instanceof LocalSearchCriteria) { - // Not supported by this database layer - throw new UnsupportedCriteriaException(array($this, $criteriaInstance), self::EXCEPTION_REQUIRED_INTERFACE_MISSING); - } - // Create full path name $pathName = $this->getSavePath() . $tableName . '/'; @@ -640,7 +634,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend * @return void * @throws SqlException If an SQL error occurs */ - public function insertDataSet (StoreableCriteria $dataSetInstance) { + public function queryInsertDataSet (StoreableCriteria $dataSetInstance) { // Create full path name $fqfn = sprintf("%s%s/%s.%s", $this->getSavePath(), diff --git a/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php b/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php index 88bc13f..1edd236 100644 --- a/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php +++ b/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php @@ -139,7 +139,7 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper { $registrationInstance->addElementsToDataSet($dataSetInstance); // "Insert" this request instance completely into the database - $this->getDatabaseInstance()->insertDataSet($dataSetInstance); + $this->getDatabaseInstance()->queryInsertDataSet($dataSetInstance); } } diff --git a/inc/classes/main/debug/class_DebugConsoleOutput.php b/inc/classes/main/debug/class_DebugConsoleOutput.php index f7dbea7..77b28b4 100644 --- a/inc/classes/main/debug/class_DebugConsoleOutput.php +++ b/inc/classes/main/debug/class_DebugConsoleOutput.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 DebugConsoleOutput extends BaseFrameworkSystem implements Debugger, OutputStreamer { +class DebugConsoleOutput extends BaseFrameworkSystem implements Debugger, OutputStreamer, Registerable { /** * Protected constructor * diff --git a/inc/classes/main/helper/login/.htaccess b/inc/classes/main/helper/login/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/helper/login/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/helper/login/class_BaseLoginHelper.php b/inc/classes/main/helper/login/class_BaseLoginHelper.php new file mode 100644 index 0000000..25be6a9 --- /dev/null +++ b/inc/classes/main/helper/login/class_BaseLoginHelper.php @@ -0,0 +1,38 @@ + + * @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 BaseLoginHelper extends BaseHelper { + /** + * Protected constructor + * + * @param $className Real name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/registration/class_BaseRegistration.php b/inc/classes/main/registration/class_BaseRegistration.php index 3066d29..aec7e5a 100644 --- a/inc/classes/main/registration/class_BaseRegistration.php +++ b/inc/classes/main/registration/class_BaseRegistration.php @@ -3,10 +3,10 @@ * A general registration class * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 diff --git a/inc/classes/main/registry/class_Registry.php b/inc/classes/main/registry/class_Registry.php index a8abb50..308e89c 100644 --- a/inc/classes/main/registry/class_Registry.php +++ b/inc/classes/main/registry/class_Registry.php @@ -3,10 +3,10 @@ * A registry for several data types * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 diff --git a/inc/classes/main/result/class_DatabaseResult.php b/inc/classes/main/result/class_DatabaseResult.php index 3d48861..c6a0b11 100644 --- a/inc/classes/main/result/class_DatabaseResult.php +++ b/inc/classes/main/result/class_DatabaseResult.php @@ -3,10 +3,10 @@ * A database result class * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class DatabaseResult extends BaseFrameworkSystem { +class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, SeekableIterator { /** * Current position in array */ @@ -97,7 +97,7 @@ class DatabaseResult extends BaseFrameworkSystem { // Is the result valid? if ($this->resultArray['status'] === "ok") { // The status is fine so let's have a look for the next entry - if (isset($this->resultArray['rows'][($this->currentPos + 1)])) { + if ($this->valid()) { // Next entry found, so count one up and cache it $this->currentPos++; $this->currentRow = $this->resultArray['rows'][$this->currentPos]; @@ -108,6 +108,89 @@ class DatabaseResult extends BaseFrameworkSystem { // Return the result return $nextValid; } + + /** + * Seeks for to a specified position + * + * @param $index Index to seek for + * @return void + */ + public function seek ($index) { + // Rewind to beginning + $this->rewind(); + + // Search for the entry + while ($this->currentPos < $index && ($this->valid())) { + // Continue on + $this->next(); + } // END - while + } + + /** + * Gives back the current position or null if not found + * + * @return $current Current element to give back + */ + public function current () { + // Default is not found + $current = null; + + // Does the current enty exist? + if (isset($this->resultArray['rows'][$this->currentPos])) { + // Then get it + $current = $this->resultArray['rows'][$this->currentPos]; + } // END - if + + // Return the result + return $current; + } + + /** + * Checks if next() and rewind will give a valid result + * + * @return $isValid Wether the next/rewind entry is valid + */ + public function valid () { + // By default nothing is valid + $isValid = false; + + // Check if + if ((isset($this->resultArray['rows'][($this->currentPos + 1)])) && (isset($this->resultArray['rows'][0]))) { + // All fine! + $isValid = true; + } // END - if + + // Return the result + return $isValid; + } + + /** + * Gets the current key of iteration + * + * @return $currentPos Key from iterator + */ + public function key () { + return $this->currentPos; + } + + /** + * Rewind to the beginning + * + * @return void + */ + public function rewind () { + $this->currentPos = 0; + } + + /** + * Searches for an entry in the data result and returns it + * + * @param $criteriaInstance The criteria to look inside the data set + * @return $result Found result entry + */ + public function searchEntry (LocalSearchCriteria $criteriaInstance) { + die("OK"); + } } // [EOF] diff --git a/inc/classes/main/rng/class_RandomNumberGenerator.php b/inc/classes/main/rng/class_RandomNumberGenerator.php index b50af11..8875a4c 100644 --- a/inc/classes/main/rng/class_RandomNumberGenerator.php +++ b/inc/classes/main/rng/class_RandomNumberGenerator.php @@ -3,10 +3,10 @@ * A standard random number generator * * @author Roland Haeder - * @version 0.3.0 + * @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.mxchange.org + * @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 diff --git a/inc/classes/main/user/class_User.php b/inc/classes/main/user/class_User.php index 25e2cc3..302c117 100644 --- a/inc/classes/main/user/class_User.php +++ b/inc/classes/main/user/class_User.php @@ -35,6 +35,7 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable { // Exceptions const EXCEPTION_USERNAME_NOT_FOUND = 0xd00; const EXCEPTION_USER_EMAIL_NOT_FOUND = 0xd01; + const EXCEPTION_USER_PASS_MISMATCH = 0xd02; /** * Protected constructor @@ -147,8 +148,8 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable { * @return $exists Wether the username exists */ public function ifUsernameExists () { - // By default the username does exist - $exists = true; + // By default the username does not exist + $exists = false; // Get a UserDatabaseWrapper instance $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper'); @@ -164,9 +165,9 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable { $result = $wrapperInstance->doSelectByCriteria($criteriaInstance); // Search for it - if (!$result->next()) { - // Entry not found - $exists = false; + if ($result->next()) { + // Entry found + $exists = true; } // END - if // Return the status @@ -179,8 +180,8 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable { * @return $exists Wether the email exists */ public function ifEmailAddressExists () { - // By default the username does exist - $exists = true; + // By default the email does not exist + $exists = false; // Get a UserDatabaseWrapper instance $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper'); @@ -196,14 +197,62 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable { $result = $wrapperInstance->doSelectByCriteria($criteriaInstance); // Search for it - if (!$result->next()) { - // Entry not found - $exists = false; + if ($result->next()) { + // Entry found + $exists = true; } // END - if // Return the status return $exists; } + + /** + * Checks if the supplied password hash in request matches with the stored + * in database. + * + * @param $requestInstance A requestable class instance + * @return $matches Wether the supplied password hash matches + */ + public function ifPasswordHashMatches (Requestable $requestInstance) { + // By default nothing matches... ;) + $matches = false; + + // Get a UserDatabaseWrapper instance + $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper'); + + // Create a search criteria + $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria'); + + // Add the username as a criteria and set limit to one entry + $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName()); + $criteriaInstance->setLimit(1); + + // Get a search result + $result = $wrapperInstance->doSelectByCriteria($criteriaInstance); + + // Search for it + if ($result->next()) { + // Get the current entry (can only be one!) + $entry = $result->current(); + + // So does the hashes match? + $matches = ($requestInstance->getRequestElement('pass_hash') === $entry['pass_hash']); + } // END - if + + // Return the status + return $matches; + } + + /** + * Adds data for later complete update + * + * @param $column Column we want to update + * @param $value New value to store in database + * @return void + */ + public function addUpdateData ($column, $value) { + $this->partialStub("Column={$column}, value={$value}"); + } } // [EOF] diff --git a/inc/classes/middleware/database/class_DatabaseConnection.php b/inc/classes/middleware/database/class_DatabaseConnection.php index 0c42807..d5661d2 100644 --- a/inc/classes/middleware/database/class_DatabaseConnection.php +++ b/inc/classes/middleware/database/class_DatabaseConnection.php @@ -158,12 +158,12 @@ class DatabaseConnection extends BaseMiddleware implements DatabaseConnector, Re * @param $dataSetInstance A storeable data set * @return void */ - public function insertDataSet (StoreableCriteria $dataSetInstance) { + public function queryInsertDataSet (StoreableCriteria $dataSetInstance) { // Connect to the database $this->dbLayer->connectToDatabase(); // Ask the database layer - $this->dbLayer->insertDataSet($dataSetInstance); + $this->dbLayer->queryInsertDataSet($dataSetInstance); } } -- 2.39.5