class_ShipSimuGuestLogin.php

Go to the documentation of this file.
00001 <?php
00024 class ShipSimuGuestLogin extends BaseFrameworkSystem implements LoginableUser {
00028         private $hashedPassword = "";
00029 
00035         protected function __construct () {
00036                 // Call parent constructor
00037                 parent::__construct(__CLASS__);
00038 
00039                 // Clean up a little
00040                 $this->removeNumberFormaters();
00041                 $this->removeSystemArray();
00042         }
00043 
00049         public final static function createShipSimuGuestLogin () {
00050                 // Get a new instance
00051                 $loginInstance = new ShipSimuGuestLogin();
00052 
00053                 // Return the instance
00054                 return $loginInstance;
00055         }
00056 
00072         public function doLogin (Requestable $requestInstance, Responseable $responseInstance) {
00073                 // By default no method is selected
00074                 $method = null;
00075                 $data = "";
00076 
00077                 // Detect login method (username or email) and try to get a userinstance
00078                 if (!is_null($requestInstance->getRequestElement('user'))) {
00079                         // Username found!
00080                         $method = 'createGuestByUsername';
00081                         $data = $requestInstance->getRequestElement('user');
00082                 } // END - if
00083 
00084                 // Is a method detected?
00085                 if (is_null($method)) {
00086                         // Then abort here
00087                         throw new UserAuthMethodException($this, self::EXCEPTION_MISSING_METHOD);
00088                 } elseif (!method_exists($this->getConfigInstance()->readConfig('guest_class'), $method)) {
00089                         // The method is invalid!
00090                         throw new MissingMethodException(array($this, $method), self::EXCEPTION_MISSING_METHOD);
00091                 }
00092 
00093                 // Get a instance of the registry
00094                 $userInstance = Registry::getRegistry()->getInstance('user');
00095 
00096                 // Is there an instance?
00097                 if (is_null($userInstance)) {
00098                         // Get a user instance
00099                         $userInstance = call_user_func_array(array($this->getConfigInstance()->readConfig('guest_class'), $method), array($data));
00100 
00101                         // Remember this new instance in registry
00102                         Registry::getRegistry()->addInstance($userInstance);
00103                 } // END - if
00104 
00105                 // Is the password correct?
00106                 if ($userInstance->ifPasswordHashMatches($requestInstance) === false) {
00107                         // Mismatching password
00108                         throw new UserPasswordMismatchException(array($this, $userInstance), BaseUser::EXCEPTION_USER_PASS_MISMATCH);
00109                 } // END - if
00110 
00111                 // Now do the real login. This can be cookie- or session-based login
00112                 // which depends on the admins setting then on the user's taste.
00113                 // 1) Get a login helper instance
00114                 $helperInstance = ObjectFactory::createObjectByConfiguredName('login_helper_class', array($requestInstance));
00115 
00116                 // 2) Execute the login. This will now login...
00117                 $helperInstance->executeLogin($responseInstance);
00118         }
00119 
00125         public function ifLoginWasSuccessfull () {
00126                 // Is the registry key there?
00127                 $loginDone = (Registry::getRegistry()->getInstance('login') instanceof Registerable);
00128 
00129                 // Return the result
00130                 return $loginDone;
00131         }
00132 
00140         public function encryptPassword ($requestKey) {
00141                 // Check if password is found in request
00142                 if ($this->getRequestInstance()->isRequestElementSet($requestKey)) {
00143                         // So encrypt the password and store it for later usage in
00144                         // the request:
00145 
00146                         // Get the plain password
00147                         $plainPassword = $this->getRequestInstance()->getRequestElement($requestKey);
00148 
00149                         // Get user instance
00150                         $userInstance = Registry::getRegistry()->getInstance('user');
00151 
00152                         // Get a crypto helper and hash the password
00153                         $this->hashedPassword = ObjectFactory::createObjectByConfiguredName('crypto_class')->hashString($plainPassword, $userInstance->getPasswordHash());
00154 
00155                         // Store the hash back in request
00156                         $this->getRequestInstance()->setRequestElement('pass_hash', $this->hashedPassword);
00157                 } // END - if
00158         }
00159 }
00160 
00161 // [EOF]
00162 ?>

Generated on Mon Dec 8 01:06:44 2008 for Ship-Simulator by  doxygen 1.5.6