]> git.mxchange.org Git - shipsimu.git/commitdiff
Variable name fixed in User, login continued (still unfinished)
authorRoland Häder <roland@mxchange.org>
Wed, 11 Jun 2008 17:20:41 +0000 (17:20 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 11 Jun 2008 17:20:41 +0000 (17:20 +0000)
.gitattributes
application/ship-simu/main/login/class_ShipSimuUserLogin.php
inc/classes/exceptions/user/class_UserEmailMissingException.php [new file with mode: 0644]
inc/classes/main/database/databases/class_LocalFileDatabase.php
inc/classes/main/filter/validator/class_UserNameValidatorFilter.php
inc/classes/main/user/class_User.php
inc/classes/middleware/debug/class_DebugMiddleware.php

index 4435563c5dab3a6a54cae75dc1c65921b959a583..18622e5af9f9b4dcedfa7be860efc2cc0b70ef5a 100644 (file)
@@ -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
index 2ffc777ad77035bb144781a6fcfcfcc2df4bfa0c..3721fb65f2cb1c622bcf9b8de32086960e2ce23b 100644 (file)
@@ -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 (file)
index 0000000..64aedd7
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+/**
+ * A class for non-existing user emails
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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 <u>%s</u> was not found.",
+                       $msgArray[0]->__toString(),
+                       $this->getLine(),
+                       $msgArray[1]
+               );
+
+               // Make sure everything is assigned properly
+               parent::__construct($message, $code);
+       }
+}
+
+// [EOF]
+?>
index c40fbf9490c0ec93118685ce2d772395898e066c..151698c7f28b9410837921a480688c516dc4cf62 100644 (file)
@@ -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
index 67c436fe858f414de68abf175400e0b0c951e375..6c531d26e9c4a8d60f05d704c5be0e6ad7d559e6 100644 (file)
@@ -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
index 2ea13a285e0ba040cccd495faf75ff4146b41d23..25e2cc3ffd1e5cdd2745da5d444425878062355e 100644 (file)
@@ -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;
        }
 
        /**
index 694dac66db2ddec30ca4dde7864e974cc155efe2..6a6bacff9cc24f0fa18f62ccc44c1a931bd92a4a 100644 (file)
@@ -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) {