* @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 $authMethod = "";
+
// Exception constants
- const EXCEPTION_INVALID_USER_INSTANCE = 0xf00;
+ const EXCEPTION_INVALID_USER_INSTANCE = 0x080;
/**
* Protected constructor
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);
+
// Return the prepared instance
return $helperInstance;
}
+
+ /**
+ * Setter for default login method from config
+ *
+ * @return void
+ */
+ protected function setDefaultAuthMethod () {
+ $this->authMethod = $this->getConfigInstance()->readConfig('auth_method_class');
+ }
+
+ /**
+ * 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) {
+ // Get an instance from the login method
+ $loginInstance = ObjectFactory::createObjectByName($this->authMethod, array($responseInstance));
+
+ // Set user cookie
+ $loginInstance->setUserAuth($this->getRequestInstance()->getRequestElement('username'));
+
+ // Set password cookie
+ $loginInstance->setPasswordAuth($this->getRequestInstance()->getRequestElement('pass_hash'));
+
+ // Remember this login instance for later usage
+ Registry::getRegistry()->addInstance('login', $loginInstance);
+ }
}
-// [EOF]
+//
?>