From 4127d88438d9b6582d8581b2405afbf4e0e3ca7d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 11 Jun 2008 17:20:41 +0000 Subject: [PATCH] Variable name fixed in User, login continued (still unfinished) --- .gitattributes | 1 + .../main/login/class_ShipSimuUserLogin.php | 48 ++++++++++++++++++- .../user/class_UserEmailMissingException.php | 46 ++++++++++++++++++ .../databases/class_LocalFileDatabase.php | 3 -- .../class_UserNameValidatorFilter.php | 2 + inc/classes/main/user/class_User.php | 9 ++-- .../debug/class_DebugMiddleware.php | 1 + 7 files changed, 102 insertions(+), 8 deletions(-) create mode 100644 inc/classes/exceptions/user/class_UserEmailMissingException.php diff --git a/.gitattributes b/.gitattributes index 4435563..18622e5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -222,6 +222,7 @@ inc/classes/exceptions/template/class_UnexpectedTemplateTypeException.php -text inc/classes/exceptions/template/class_UnsupportedTemplateEngineException.php -text 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_UsernameMissingException.php -text inc/classes/interfaces/.htaccess -text inc/classes/interfaces/application/.htaccess -text diff --git a/application/ship-simu/main/login/class_ShipSimuUserLogin.php b/application/ship-simu/main/login/class_ShipSimuUserLogin.php index 2ffc777..3721fb6 100644 --- a/application/ship-simu/main/login/class_ShipSimuUserLogin.php +++ b/application/ship-simu/main/login/class_ShipSimuUserLogin.php @@ -62,9 +62,55 @@ class ShipSimuUserLogin extends BaseFrameworkSystem implements LoginableUser { * * @param $requestInstance An instance of a Requestable class * @return void + * @throws UserLoginMethodException If wether username nor email login + * 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 */ public function doLogin (Requestable $requestInstance) { - $this->partialStub(); + // By default no method is selected + $method = null; + $data = ""; + + // Detect login method (username or email) and try to get a userinstance + if (!is_null($requestInstance->getRequestElement('username'))) { + // Username found! + $method = "createUserByUsername"; + $data = $requestInstance->getRequestElement('username'); + } elseif (!is_null($requestInstance->getRequestElement('email'))) { + // Email found! + $method = "createUserByEmail"; + $data = $requestInstance->getRequestElement('email'); + } + + // Is a method detected? + if (is_null($method)) { + // Then abort here + throw new UserLoginMethodException($this, self::EXCEPTION_MISSING_METHOD); + } elseif (!method_exists("User", $method)) { + // The method is invalid! + throw new MissingMethodException(array($this, $method), self::EXCEPTION_MISSING_METHOD); + } + + // Get a instance of the registry + $userInstance = Registry::getRegistry()->getInstance('user'); + + // Is there an instance? + if (is_null($userInstance)) { + // Get a user instance + $userInstance = call_user_func_array(array("User", $method), array($data)); + } // 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); + } // END - if + + // Partially finished! + $this->partialStub("userInstance set, continue with password verification"); } } diff --git a/inc/classes/exceptions/user/class_UserEmailMissingException.php b/inc/classes/exceptions/user/class_UserEmailMissingException.php new file mode 100644 index 0000000..64aedd7 --- /dev/null +++ b/inc/classes/exceptions/user/class_UserEmailMissingException.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 UserEmailMissingException 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] User email %s was not found.", + $msgArray[0]->__toString(), + $this->getLine(), + $msgArray[1] + ); + + // Make sure everything is assigned properly + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/database/databases/class_LocalFileDatabase.php b/inc/classes/main/database/databases/class_LocalFileDatabase.php index c40fbf9..151698c 100644 --- a/inc/classes/main/database/databases/class_LocalFileDatabase.php +++ b/inc/classes/main/database/databases/class_LocalFileDatabase.php @@ -649,9 +649,6 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend $this->getFileExtension() ); - // Skip here while developing - return true; - // Try to save the request away try { // Get a file pointer instance diff --git a/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php b/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php index 67c436f..6c531d2 100644 --- a/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php +++ b/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php @@ -120,9 +120,11 @@ class UserNameValidatorFilter extends BaseFrameworkSystem implements Filterable if ($registry->instanceExists('user')) { // Use the instance for checking for the email $userInstance = $registry->getInstance('user'); + $userInstance->setUserName($userName); } else { // If this instance is created then the username *does* exist try { + // Get a new instance $userInstance = User::createUserByUsername($userName); // Remember this user instance in our registry for later usage diff --git a/inc/classes/main/user/class_User.php b/inc/classes/main/user/class_User.php index 2ea13a2..25e2cc3 100644 --- a/inc/classes/main/user/class_User.php +++ b/inc/classes/main/user/class_User.php @@ -33,7 +33,8 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable { private $email = ""; // Exceptions - const EXCEPTION_USERNAME_NOT_FOUND = 0xd00; + const EXCEPTION_USERNAME_NOT_FOUND = 0xd00; + const EXCEPTION_USER_EMAIL_NOT_FOUND = 0xd01; /** * Protected constructor @@ -72,7 +73,7 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable { $userInstance = new User(); // Set the username - $userInstance->setUsername($userName); + $userInstance->setUserName($userName); // Check if the username exists if (!$userInstance->ifUsernameExists()) { @@ -108,8 +109,8 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable { * @param $userName The username to set * @return void */ - protected final function setUsername ($userName) { - $this->UserName = $userName; + public final function setUserName ($userName) { + $this->userName = $userName; } /** diff --git a/inc/classes/middleware/debug/class_DebugMiddleware.php b/inc/classes/middleware/debug/class_DebugMiddleware.php index 694dac6..6a6bacf 100644 --- a/inc/classes/middleware/debug/class_DebugMiddleware.php +++ b/inc/classes/middleware/debug/class_DebugMiddleware.php @@ -106,6 +106,7 @@ class DebugMiddleware extends BaseMiddleware implements Registerable { * browser or debug lines for a log file, etc. to the registered debug * output instance. * + * @param $outStream Data we shall "stream" out to the world * @return void */ public final function output ($outStream) { -- 2.39.5