* @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 * * 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 . */ class ShipSimuUserLogin extends BaseFrameworkSystem implements LoginableUser { /** * Protected constructor * * @return void */ protected function __construct () { // Call parent constructor parent::__construct(__CLASS__); // Set part description $this->setObjectDescription("Login for Ship-Simu"); // Create unique ID number $this->generateUniqueId(); // Clean up a little $this->removeNumberFormaters(); $this->removeSystemArray(); } /** * Creates an instance of this login class * * @return $loginInstance An instance of this login class */ public final static function createShipSimuUserLogin () { // Get a new instance $loginInstance = new ShipSimuUserLogin(); // Return the instance return $loginInstance; } /** * Logins the user with the given request containing the credential. The * result of the login can be thrown by exception or, if prefered stored * in a boolean attribute which is then readable by a matching getter. * * @param $requestInstance An instance of a Requestable class * @return void * @throws UserLoginMethodException If wether username nor email login * was detected * @throws MissingMethodException If a method was not found in the * User class * @throws UserEmailMissingException If user with given email address was * not found in database */ public function doLogin (Requestable $requestInstance) { // By default no method is selected $method = null; $data = ""; // Detect login method (username or email) and try to get a userinstance if (!is_null($requestInstance->getRequestElement('username'))) { // Username found! $method = "createUserByUsername"; $data = $requestInstance->getRequestElement('username'); } elseif (!is_null($requestInstance->getRequestElement('email'))) { // Email found! $method = "createUserByEmail"; $data = $requestInstance->getRequestElement('email'); } // Is a method detected? if (is_null($method)) { // Then abort here throw new UserLoginMethodException($this, self::EXCEPTION_MISSING_METHOD); } elseif (!method_exists("User", $method)) { // The method is invalid! throw new MissingMethodException(array($this, $method), self::EXCEPTION_MISSING_METHOD); } // Get a instance of the registry $userInstance = Registry::getRegistry()->getInstance('user'); // Is there an instance? if (is_null($userInstance)) { // Get a user instance $userInstance = call_user_func_array(array("User", $method), array($data)); } // END - if // If we have email login then check if a user account with that email exists! if (($method == "createUserByEmail") && (!$userInstance->ifEmailAddressExists())) { // The user account is missing! throw new UserEmailMissingException(array($this, $data), User::EXCEPTION_USER_EMAIL_NOT_FOUND); } // END - if // Partially finished! $this->partialStub("userInstance set, continue with password verification"); } } // [EOF] ?>