3 * A helper for administration area login. This login helper first checks what
4 * setting (cookie or session) the admin has choosen then overwrites it with the
5 * setting from current user. The registry instance should hold an instance of
6 * this user class at key 'user' else an exception will be thrown. After this
7 * the setting from a login form will be taken as login method and be stored
8 * in database for later usage.
10 * The user shall be able to choose "Default login method" or similar to use his
13 * @author Roland Haeder <webmaster@ship-simu.org>
15 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Admin-Area Developer Team
16 * @license GNU GPL 3.0 or any newer version
17 * @link http://www.ship-simu.org
19 * This program is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation, either version 3 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 class AdminLoginHelper extends BaseLoginHelper implements HelpableLogin {
34 * The login method we shall choose
36 private $authMethod = "";
38 // Exception constants
39 const EXCEPTION_INVALID_USER_INSTANCE = 0x190;
42 * Protected constructor
46 protected function __construct () {
47 // Call parent constructor
48 parent::__construct(__CLASS__);
52 * Creates an instance of this class by given request instance
54 * @param $requestInstance An instance of a Requestable class
55 * @return $helperInstance An instance of this helper class
56 * @throws UserInstanceMissingException If the user instance in registry
57 * is missing or invalid
59 public static final function createAdminLoginHelper (Requestable $requestInstance) {
60 // Get a new instance first
61 $helperInstance = new AdminLoginHelper();
63 // Get a user instance from registry
64 $userInstance = Registry::getRegistry()->getInstance('user');
66 // Is this instance valid?
67 if (!$userInstance instanceof ManageableAccount) {
68 // Thrown an exception here
69 throw new UserInstanceMissingException (array($helperInstance, 'user'), self::EXCEPTION_INVALID_USER_INSTANCE);
72 // Set default login method from config
73 $helperInstance->setDefaultAuthMethod();
75 // Set request instance
76 $helperInstance->setRequestInstance($requestInstance);
78 // Return the prepared instance
79 return $helperInstance;
83 * Setter for default login method from config
87 protected function setDefaultAuthMethod () {
88 $this->authMethod = $this->getConfigInstance()->getConfigEntry('auth_method_class');
92 * Execute the login request by given response instance. This instance can
93 * be used for sending cookies or at least the session id out.
95 * @param $responseInstance An instance of a Responseable class
98 public function executeLogin (Responseable $responseInstance) {
99 // Get an instance from the login method
100 $loginInstance = ObjectFactory::createObjectByName($this->authMethod, array($responseInstance));
103 $loginInstance->setUserAuth($this->getRequestInstance()->getRequestElement('username'));
105 // Set password cookie
106 $loginInstance->setPasswordAuth($this->getRequestInstance()->getRequestElement('pass_hash'));
108 // Remember this login instance for later usage
109 Registry::getRegistry()->addInstance('login', $loginInstance);