*
* @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
*
/**
* 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
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();
}
/**
$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);
*
* @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');
}
/**
* @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);