class_WebShipsimuUserLoginCommand.php

Go to the documentation of this file.
00001 <?php
00024 class WebShipsimuUserLoginCommand extends BaseCommand implements Commandable {
00030         protected function __construct () {
00031                 // Call parent constructor
00032                 parent::__construct(__CLASS__);
00033 
00034                 // Clean up a little
00035                 $this->removeNumberFormaters();
00036                 $this->removeSystemArray();
00037         }
00038 
00045         public final static function createWebShipsimuUserLoginCommand (CommandResolver $resolverInstance) {
00046                 // Get a new instance
00047                 $commandInstance = new WebShipsimuUserLoginCommand();
00048 
00049                 // Set the resolver instance
00050                 $commandInstance->setResolverInstance($resolverInstance);
00051 
00052                 // Return the prepared instance
00053                 return $commandInstance;
00054         }
00055 
00063         public function execute (Requestable $requestInstance, Responseable $responseInstance) {
00064                 // First get a UserLogin instance
00065                 $loginInstance = ObjectFactory::createObjectByConfiguredName('user_login_class');
00066 
00067                 // First set request and response instance
00068                 $loginInstance->setRequestInstance($requestInstance);
00069 
00070                 // Encrypt the password
00071                 $loginInstance->encryptPassword('pass');
00072 
00073                 // Do the login here
00074                 $loginInstance->doLogin($requestInstance, $responseInstance);
00075 
00076                 // Was the login fine? Then redirect here
00077                 if ($loginInstance->ifLoginWasSuccessfull()) {
00078                         // Try to redirect here
00079                         try {
00080                                 // Redirect...
00081                                 $responseInstance->redirectToConfiguredUrl('app_login_url');
00082 
00083                                 // Exit here
00084                                 exit();
00085                         } catch (FrameworkException $e) {
00086                                 // Something went wrong here!
00087                                 $responseInstance->addFatalMessage($e->getMessage());
00088                         }
00089                 } else {
00090                         // Attach error message to the response
00091                         $responseInstance->addFatalMessage('failed_user_login');
00092                 }
00093         }
00094 
00103         public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
00104                 // Which login type do we have?
00105                 switch ($this->getConfigInstance()->readConfig('login_type')) {
00106                         case "username": // Login via username
00107                                 $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('username_verifier_filter'));
00108                                 break;
00109 
00110                         case "email": // Login via email
00111                                 $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('email_verifier_filter'));
00112                                 break;
00113 
00114                         default: // Wether username or email is set
00115                                 $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('username_email_verifier_filter'));
00116                                 break;
00117                 }
00118 
00119                 // Password verifier filter
00120                 $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('password_verifier_filter'));
00121 
00122                 // Add filter for CAPTCHA
00123                 $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('captcha_user_verifier_filter'));
00124         }
00125 }
00126 
00127 // [EOF]
00128 ?>

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