]> git.mxchange.org Git - shipsimu.git/blobdiff - application/ship-simu/main/login/helper/class_ShipSimuLoginHelper.php
Cookie-based login initially done
[shipsimu.git] / application / ship-simu / main / login / helper / class_ShipSimuLoginHelper.php
index 13bed29d1e8ee961b2e95fd131be8f0f2dcc7e93..9dd7f96fb34a815a11e1b2e6c13a9b8a29af9347 100644 (file)
@@ -15,7 +15,6 @@
  * @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
  * 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 ShipSimuLoginHelper extends BaseLoginHelper {
+class ShipSimuLoginHelper extends BaseLoginHelper implements HelpableLogin {
+       /**
+        * The login method we shall choose
+        */
+       private $loginMethod = "";
+
+       /**
+        * Instance for a request class
+        */
+       private $requestInstance = null;
+
        // Exception constants
        const EXCEPTION_INVALID_USER_INSTANCE = 0xf00;
 
@@ -88,11 +97,67 @@ class ShipSimuLoginHelper extends BaseLoginHelper {
                        // Set default login method from config
                        $helperInstance->setDefaultLoginMethod();
                }
-               
+
+               // Set request instance
+               $helperInstance->setRequestInstance($requestInstance);
+
                // Return the prepared instance
                return $helperInstance;
        }
+
+       /**
+        * Setter for default login method from config
+        *
+        * @return      void
+        */
+       protected function setDefaultLoginMethod () {
+               $this->loginMethod = $this->getConfigInstance()->readConfig('login_method');
+       }
+
+       /**
+        * Setter for request instance
+        *
+        * @param       $requestInstance        A Requestable class instance
+        * @return      void
+        */
+       public final function setRequestInstance (Requestable $requestInstance) {
+               $this->requestInstance = $requestInstance;
+       }
+
+       /**
+        * Getter for request instance
+        *
+        * @param       
+        * @return      $requestInstance        A Requestable class instance
+        */
+       public final function getRequestInstance () {
+               return $this->requestInstance;
+       }
+
+       /**
+        * Execute the login request by given response instance. This instance can
+        * be used for sending cookies or at least the session id out.
+        *
+        * @param       $responseInstance       An instance of a Responseable class
+        * @return      void
+        */
+       public function executeLogin (Responseable $responseInstance) {
+               // First create the requested login method name
+               $loginMethodClass = ucfirst(strtolower($this->loginMethod)) . "Login";
+
+               // Then try to get an instance from it
+               $loginInstance = ObjectFactory::createObjectByName($loginMethodClass, array($responseInstance));
+
+               // Set user cookie
+               $loginInstance->setUserAuth($this->requestInstance->getRequestElement('username'));
+
+               // Set password cookie
+               $loginInstance->setPasswordAuth($this->requestInstance->getRequestElement('pass_hash'));
+
+               // Remember this login instance for later usage
+               Registry::getRegistry()->addInstance('login', $loginInstance);
+       }
 }
 
-// [EOF]
+//
 ?>