X-Git-Url: https://git.mxchange.org/?p=shipsimu.git;a=blobdiff_plain;f=application%2Fship-simu%2Fmain%2Flogin%2Fhelper%2Fclass_ShipSimuLoginHelper.php;h=32da33fe2b45de746b7c8dead80a62647e6a9fe7;hp=13bed29d1e8ee961b2e95fd131be8f0f2dcc7e93;hb=0f10df895de1dd67a2bbec5264f01c5e146de952;hpb=fd80d47afc96ae0c0759530800051a0f07eb9c92 diff --git a/application/ship-simu/main/login/helper/class_ShipSimuLoginHelper.php b/application/ship-simu/main/login/helper/class_ShipSimuLoginHelper.php index 13bed29..32da33f 100644 --- a/application/ship-simu/main/login/helper/class_ShipSimuLoginHelper.php +++ b/application/ship-simu/main/login/helper/class_ShipSimuLoginHelper.php @@ -12,10 +12,9 @@ * * @author Roland Haeder * @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 - * @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 @@ -30,9 +29,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -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 = 0x190; /** * Protected constructor @@ -42,12 +46,6 @@ class ShipSimuLoginHelper extends BaseLoginHelper { 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(); } /** @@ -66,33 +64,51 @@ class ShipSimuLoginHelper extends BaseLoginHelper { $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'); + // Set default login method from config + $helperInstance->setDefaultAuthMethod(); - // 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); + // Set request instance + $helperInstance->setRequestInstance($requestInstance); - // 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(); - } - // Return the prepared instance return $helperInstance; } + + /** + * Setter for default login method from config + * + * @return void + */ + protected function setDefaultAuthMethod () { + $this->authMethod = $this->getConfigInstance()->getConfigEntry('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] +// ?>