]> git.mxchange.org Git - shipsimu.git/blobdiff - application/ship-simu/main/login/class_ShipSimuUserLogin.php
Variable name fixed in User, login continued (still unfinished)
[shipsimu.git] / application / ship-simu / main / login / class_ShipSimuUserLogin.php
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");
        }
 }