--- /dev/null
+<?php
+/**
+ * A helper for Ship-Simu to login. This login helper first checks what setting
+ * (cookie or session) the admin has choosen then overwrites it with the setting
+ * from current user. The registry instance should hold an instance of this user
+ * class at key 'user' else an exception will be thrown. After this the setting
+ * from a login form will be taken as login method and be stored in database
+ * for later usage.
+ *
+ * The user shall be able to choose "Default login method" or similar to use his
+ * own login method.
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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 {
+ // Exception constants
+ const EXCEPTION_INVALID_USER_INSTANCE = 0xf00;
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ 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();
+ }
+
+ /**
+ * Creates an instance of this class by given request instance
+ *
+ * @param $requestInstance An instance of a Requestable class
+ * @return $helperInstance An instance of this helper class
+ * @throws UserInstanceMissingException If the user instance in registry
+ * is missing or invalid
+ */
+ public final static function createShipSimuLoginHelper (Requestable $requestInstance) {
+ // Get a new instance first
+ $helperInstance = new ShipSimuLoginHelper();
+
+ // Get a user instance from registry
+ $userInstance = Registry::getRegistry()->getInstance('user');
+
+ // Is this instance valid?
+ if (!$userInstance instanceof ManageableUser) {
+ // 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();
+ }
+
+ // Return the prepared instance
+ return $helperInstance;
+ }
+}
+
+// [EOF]
+?>