]> git.mxchange.org Git - shipsimu.git/blobdiff - application/ship-simu/main/login/helper/class_ShipSimuLoginHelper.php
readConfig() is not naming convention, renamed to getConfigEntry()
[shipsimu.git] / application / ship-simu / main / login / helper / class_ShipSimuLoginHelper.php
index 9dd7f96fb34a815a11e1b2e6c13a9b8a29af9347..32da33fe2b45de746b7c8dead80a62647e6a9fe7 100644 (file)
@@ -12,7 +12,7 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright(c) 2007, 2008 Roland Haeder, this is free software
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  *
@@ -33,15 +33,10 @@ class ShipSimuLoginHelper extends BaseLoginHelper implements HelpableLogin {
        /**
         * The login method we shall choose
         */
-       private $loginMethod = "";
-
-       /**
-        * Instance for a request class
-        */
-       private $requestInstance = null;
+       private $authMethod = "";
 
        // Exception constants
-       const EXCEPTION_INVALID_USER_INSTANCE = 0xf00;
+       const EXCEPTION_INVALID_USER_INSTANCE = 0x190;
 
        /**
         * Protected constructor
@@ -51,12 +46,6 @@ class ShipSimuLoginHelper extends BaseLoginHelper implements HelpableLogin {
        protected function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
-
-               // Set part description
-               $this->setObjectDescription("Login helper for Ship-Simu");
-
-               // Create unique ID number
-               $this->generateUniqueId();
        }
 
        /**
@@ -75,28 +64,13 @@ class ShipSimuLoginHelper extends BaseLoginHelper implements HelpableLogin {
                $userInstance = Registry::getRegistry()->getInstance('user');
 
                // Is this instance valid?
-               if (!$userInstance instanceof ManageableUser) {
+               if (!$userInstance instanceof ManageableAccount) {
                        // Thrown an exception here
                        throw new UserInstanceMissingException (array($helperInstance, 'user'), self::EXCEPTION_INVALID_USER_INSTANCE);
                } // END - if
 
-               // Get the login method from request
-               $methodRequest = $requestInstance->getRequestElement('login_method');
-
-               // Now, if that wents fine we can check if the request includes a login method entry
-               if ((!is_null($methodRequest)) && ($methodRequest != "default") && ($methodRequest != $userInstance->getLoginMethod())) {
-                       // Okay, the login method has been choosen by user so remember it
-                       $helperInstance->setLoginMethod($methodRequest);
-
-                       // Remeber that we need to update the user account as well
-                       $userInstance->addUpdateData('login_method', $methodRequest);
-               } elseif (($methodRequest == "default") && (is_string($userInstance->getLoginMethod()))) {
-                       // Choose default method from user
-                       $helperInstance->setLoginMethod($userInstance->getLoginMethod());
-               } else {
-                       // Set default login method from config
-                       $helperInstance->setDefaultLoginMethod();
-               }
+               // Set default login method from config
+               $helperInstance->setDefaultAuthMethod();
 
                // Set request instance
                $helperInstance->setRequestInstance($requestInstance);
@@ -110,28 +84,8 @@ class ShipSimuLoginHelper extends BaseLoginHelper implements HelpableLogin {
         *
         * @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;
+       protected function setDefaultAuthMethod () {
+               $this->authMethod = $this->getConfigInstance()->getConfigEntry('auth_method_class');
        }
 
        /**
@@ -142,17 +96,14 @@ class ShipSimuLoginHelper extends BaseLoginHelper implements HelpableLogin {
         * @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));
+               // Get an instance from the login method
+               $loginInstance = ObjectFactory::createObjectByName($this->authMethod, array($responseInstance));
 
                // Set user cookie
-               $loginInstance->setUserAuth($this->requestInstance->getRequestElement('username'));
+               $loginInstance->setUserAuth($this->getRequestInstance()->getRequestElement('username'));
 
                // Set password cookie
-               $loginInstance->setPasswordAuth($this->requestInstance->getRequestElement('pass_hash'));
+               $loginInstance->setPasswordAuth($this->getRequestInstance()->getRequestElement('pass_hash'));
 
                // Remember this login instance for later usage
                Registry::getRegistry()->addInstance('login', $loginInstance);