From 721ba61ffed98cdbabc8860d27dd21b104118221 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 18 Jun 2008 21:29:17 +0000 Subject: [PATCH] Auth filter basicly completed, user update filter added (stubs), minor fixes --- .gitattributes | 2 + application/ship-simu/config.php | 9 +- .../login/class_WebLoginAreaController.php | 11 ++- .../main/filter/auth/class_UserAuthFilter.php | 17 +++- inc/classes/main/filter/update/.htaccess | 1 + .../filter/update/class_UserUpdateFilter.php | 82 +++++++++++++++++++ .../main/result/class_DatabaseResult.php | 2 +- 7 files changed, 116 insertions(+), 8 deletions(-) create mode 100644 inc/classes/main/filter/update/.htaccess create mode 100644 inc/classes/main/filter/update/class_UserUpdateFilter.php diff --git a/.gitattributes b/.gitattributes index 05dd822..0ff33d2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -394,6 +394,8 @@ inc/classes/main/filter/news/class_NewsDownloadFilter.php -text inc/classes/main/filter/news/class_NewsProcessFilter.php -text inc/classes/main/filter/null/.htaccess -text inc/classes/main/filter/null/class_NullFilter.php -text +inc/classes/main/filter/update/.htaccess -text +inc/classes/main/filter/update/class_UserUpdateFilter.php -text inc/classes/main/filter/validator/.htaccess -text inc/classes/main/filter/validator/class_EmailValidatorFilter.php -text inc/classes/main/filter/validator/class_PasswordValidatorFilter.php -text diff --git a/application/ship-simu/config.php b/application/ship-simu/config.php index 0217b61..9c000d8 100644 --- a/application/ship-simu/config.php +++ b/application/ship-simu/config.php @@ -94,15 +94,18 @@ $cfg->setConfigEntry('login_default_action', "welcome"); // CFG: NEWS-READER-CLASS $cfg->setConfigEntry('news_reader_class', "DefaultNewsReader"); -// CFG: NEWS-DOWNLOAD-FILTER +// CFG: NEWS-DOWNLOAD-CLASS $cfg->setConfigEntry('news_download_class', "NewsDownloadFilter"); -// CFG: NEWS-PROCESS-FILTER +// CFG: NEWS-PROCESS-CLASS $cfg->setConfigEntry('news_process_class', "NewsProcessFilter"); -// CFG: USER-AUTH-FILTER +// CFG: USER-AUTH-CLASS $cfg->setConfigEntry('user_auth_class', "UserAuthFilter"); +// CFG: USER-UPDATE-CLASS +$cfg->setConfigEntry('user_update_class', "UserUpdateFilter"); + // CFG: NEWS-HOME-LIMIT $cfg->setConfigEntry('news_home_limit', 10); diff --git a/inc/classes/main/controller/login/class_WebLoginAreaController.php b/inc/classes/main/controller/login/class_WebLoginAreaController.php index 883cfca..7ea4e50 100644 --- a/inc/classes/main/controller/login/class_WebLoginAreaController.php +++ b/inc/classes/main/controller/login/class_WebLoginAreaController.php @@ -51,11 +51,20 @@ class WebLoginAreaController extends BaseController implements Controller { // Set the command resolver $controllerInstance->setResolverInstance($resolverInstance); - // Add some filters to this controller + // User auth filter $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_auth_class')); + + // User update filter + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_update_class')); + + // News fetcher filter $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_download_class')); + + // News proccess/display-preparation $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_process_class')); + /* @TODO: Add some filters to this controller */ + // Return the prepared instance return $controllerInstance; } diff --git a/inc/classes/main/filter/auth/class_UserAuthFilter.php b/inc/classes/main/filter/auth/class_UserAuthFilter.php index 5754bf1..dac1ebc 100644 --- a/inc/classes/main/filter/auth/class_UserAuthFilter.php +++ b/inc/classes/main/filter/auth/class_UserAuthFilter.php @@ -78,6 +78,7 @@ class UserAuthFilter extends BaseFilter implements Filterable { * @param $responseInstance An instance of a class with an Responseable interface * @return void * @throws UserAuthorizationException If the auth login was not found or if it was invalid + * @throws UserPasswordMismatchException If the supplied password hash does not match */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Then get an auth instance for checking and updating the auth cookies @@ -103,10 +104,20 @@ class UserAuthFilter extends BaseFilter implements Filterable { // Stop here throw new UserAuthorizationException($this, self::EXCEPTION_AUTH_DATA_INVALID); - } + } // END - if - // Destroy safely the auth instance - unset($authInstance); + // Now, try to get a user instance + $userInstance = User::createUserByUserName($authLogin); + + // Is the password correct? + if ($userInstance->getPasswordHash() !== $authHash) { + // Mismatching password + throw new UserPasswordMismatchException(array($this, $userInstance), User::EXCEPTION_USER_PASS_MISMATCH); + } // END - if + + // Remember auth and user instances in registry + Registry::getRegistry()->addInstance('auth', $authInstance); + Registry::getRegistry()->addInstance('user', $userInstance); } } diff --git a/inc/classes/main/filter/update/.htaccess b/inc/classes/main/filter/update/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/filter/update/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/filter/update/class_UserUpdateFilter.php b/inc/classes/main/filter/update/class_UserUpdateFilter.php new file mode 100644 index 0000000..b8f598f --- /dev/null +++ b/inc/classes/main/filter/update/class_UserUpdateFilter.php @@ -0,0 +1,82 @@ + + * @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 UserUpdateFilter extends BaseFrameworkSystem implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("User update filter"); + + // Create unique ID number + $this->generateUniqueId(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function createUserUpdateFilter () { + // Get a new instance + $filterInstance = new UserUpdateFilter(); + + // 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 user instance from registry + $userInstance = Registry::getRegistry()->getInstance('user'); + + // Now update last activity + $userInstance->updateLastActivity(); + + // Update auth data as well + /* @TODO Add more user updates here */ + + // Write all updates to the database + $userInstance->flushUpdates(); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/result/class_DatabaseResult.php b/inc/classes/main/result/class_DatabaseResult.php index 0175472..fb02af3 100644 --- a/inc/classes/main/result/class_DatabaseResult.php +++ b/inc/classes/main/result/class_DatabaseResult.php @@ -192,7 +192,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Se * @return $result Found result entry */ public function searchEntry (LocalSearchCriteria $criteriaInstance) { - die("OK"); + die(__METHOD__.": OK"); } } -- 2.30.2