]> git.mxchange.org Git - shipsimu.git/commitdiff
Several fixes (new class/filters) for guest login
authorRoland Häder <roland@mxchange.org>
Wed, 25 Jun 2008 11:00:10 +0000 (11:00 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 25 Jun 2008 11:00:10 +0000 (11:00 +0000)
13 files changed:
.gitattributes
application/ship-simu/main/commands/web/class_WebShipsimuGuestLoginCommand.php
application/ship-simu/main/commands/web/class_WebShipsimuProfileCommand.php
application/ship-simu/main/login/class_ShipSimuGuestLogin.php
application/ship-simu/main/registration/class_ShipSimuRegistration.php
inc/classes/main/controller/web/class_WebLogoutDoneController.php [new file with mode: 0644]
inc/classes/main/filter/auth/class_UserAuthFilter.php
inc/classes/main/filter/guest/class_UserNameIsGuestFilter.php
inc/classes/main/filter/verifier/class_PasswordGuestVerifierFilter.php [new file with mode: 0644]
inc/classes/main/filter/verifier/class_UserGuestVerifierFilter.php [new file with mode: 0644]
inc/classes/main/response/class_HttpResponse.php
inc/config.php
inc/config/class_FrameworkConfiguration.php

index 74a28e0bc79e0ba0d2d32aab7097e0110768d0ec..55178417d83919fba809c145e9887569aea6c4c9 100644 (file)
@@ -412,6 +412,7 @@ inc/classes/main/controller/web/class_WebDefaultController.php -text
 inc/classes/main/controller/web/class_WebDefaultNewsController.php -text
 inc/classes/main/controller/web/class_WebLoginController.php -text
 inc/classes/main/controller/web/class_WebLoginFailedController.php -text
+inc/classes/main/controller/web/class_WebLogoutDoneController.php -text
 inc/classes/main/controller/web/class_WebRegisterController.php -text
 inc/classes/main/criteria/.htaccess -text
 inc/classes/main/criteria/class_DataSetCriteria.php -text
@@ -474,7 +475,9 @@ inc/classes/main/filter/validator/class_UserNameValidatorFilter.php -text
 inc/classes/main/filter/verifier/.htaccess -text
 inc/classes/main/filter/verifier/class_AccountPasswordVerifierFilter.php -text
 inc/classes/main/filter/verifier/class_EmailValidatorFilter.php -text
+inc/classes/main/filter/verifier/class_PasswordGuestVerifierFilter.php -text
 inc/classes/main/filter/verifier/class_PasswordVerifierFilter.php -text
+inc/classes/main/filter/verifier/class_UserGuestVerifierFilter.php -text
 inc/classes/main/filter/verifier/class_UserNameVerifierFilter.php -text
 inc/classes/main/filter/verifier/class_UserStatusVerifierFilter.php -text
 inc/classes/main/filter/verifier/class_UserUnconfirmedVerifierFilter.php -text
index 9d747de6b100eb484f7a4bdc2b0add9617c1ff44..eedc22ce3a5622ca977418aa691dde9e9a606d24 100644 (file)
@@ -74,7 +74,7 @@ class WebShipsimuGuestLoginCommand extends BaseCommand implements Commandable {
                $loginInstance->setRequestInstance($requestInstance);
 
                // Encrypt the password
-               $loginInstance->encryptPassword('pass');
+               $loginInstance->encryptPassword('passwd');
 
                // Do the login here
                $loginInstance->doLogin($requestInstance, $responseInstance);
@@ -103,23 +103,11 @@ class WebShipsimuGuestLoginCommand extends BaseCommand implements Commandable {
         * @todo        Add more filters
         */
        public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
-               // Which login type do we have?
-               switch ($this->getConfigInstance()->readConfig('login_type')) {
-                       case "username": // Login via username
-                               $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('username_verifier_class'));
-                               break;
-
-                       case "email": // Login via email
-                               $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('email_verifier_class'));
-                               break;
-
-                       default: // Wether username or email is set
-                               $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('username_email_verifier_class'));
-                               break;
-               }
+               // Add username
+               $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_guest_verifier_class'));
 
                // Add password verifier filter
-               $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('password_verifier_class'));
+               $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('passwd_guest_verifier_class'));
        }
 }
 
index 107d093d683312d24871380a4f1e0bdecaa4d5f2..5a0520f5b4115d12c48315be8acd757cebdb9af9 100644 (file)
@@ -113,7 +113,8 @@ class WebShipsimuProfileCommand extends BaseCommand implements Commandable {
                unset($this->allowedData);
 
                // Unfinished!
-               $this->debugInstance();
+               $this->partialStub("Unfinished work.");
+               $this->debugBackTrace();
        }
 
        /**
index 4fe5915bac3c5247ef1a10297b6d4b7093d51ef5..47af7cdea54b75ecce8b91c5cffb3e7b6ef479da 100644 (file)
@@ -81,14 +81,10 @@ class ShipSimuGuestLogin extends BaseFrameworkSystem implements LoginableUser {
                $data = "";
 
                // Detect login method (username or email) and try to get a userinstance
-               if (!is_null($requestInstance->getRequestElement('username'))) {
+               if (!is_null($requestInstance->getRequestElement('user'))) {
                        // Username found!
                        $method = "createGuestByUsername";
-                       $data = $requestInstance->getRequestElement('username');
-               } elseif (!is_null($requestInstance->getRequestElement('email'))) {
-                       // Email found!
-                       $method = "createGuestByEmail";
-                       $data = $requestInstance->getRequestElement('email');
+                       $data = $requestInstance->getRequestElement('user');
                }
 
                // Is a method detected?
index 87a4429128e9572e873a7ff2d842f349fb94fa98..f625eacdd8a1e2f0d791215b21dfb2649149a0c3 100644 (file)
@@ -174,7 +174,7 @@ class ShipSimuRegistration extends BaseRegistration {
                        }
 
                        // Is this a guest account?
-                       if ((($element == "username") || ($alias == "username")) && ($this->getRequestInstance()->getRequestElement($element) == $this->getConfigInstance()->readConfig('guest_login_username'))) {
+                       if ((($element == "username") || ($alias == "username")) && ($this->getRequestInstance()->getRequestElement($element) == $this->getConfigInstance()->readConfig('guest_login_user'))) {
                                // Yes, then set the config entry to guest status
                                $configEntry = 'user_status_guest';
                        } // END - if
diff --git a/inc/classes/main/controller/web/class_WebLogoutDoneController.php b/inc/classes/main/controller/web/class_WebLogoutDoneController.php
new file mode 100644 (file)
index 0000000..dce9fab
--- /dev/null
@@ -0,0 +1,92 @@
+<?php
+/**
+ * Controller for logout done page
+ *
+ * @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
+ *
+ * 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 WebLogoutDoneController extends BaseController implements Controller {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set part description
+               $this->setObjectDescription("Controller for login form");
+
+               // Create unique ID number
+               $this->generateUniqueId();
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @param       $resolverInstance               An instance of a command resolver class
+        * @return      $controllerInstance             A prepared instance of this class
+        * @todo        Add some filters to this controller
+        */
+       public final static function createWebLogoutDoneController (CommandResolver $resolverInstance) {
+               // Create the instance
+               $controllerInstance = new WebLogoutDoneController();
+
+               // Set the command resolver
+               $controllerInstance->setResolverInstance($resolverInstance);
+
+
+               // Return the prepared instance
+               return $controllerInstance;
+       }
+
+       /**
+        * Handles the given request and response
+        *
+        * @param       $requestInstance        An instance of a request class
+        * @param       $responseInstance       An instance of a response class
+        * @return      void
+        */
+       public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) {
+               // Get the command instance from the resolver by sending a request instance to the resolver
+               $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance);
+
+               // Add more filters by the command
+               $commandInstance->addExtraFilters($this, $requestInstance);
+
+               // Run the pre filters
+               $this->executePreFilters($requestInstance, $responseInstance);
+
+               // This request was valid! :-D
+               $requestInstance->requestIsValid();
+
+               // Execute the command
+               $commandInstance->execute($requestInstance, $responseInstance);
+
+               // Run the pre filters
+               $this->executePostFilters($requestInstance, $responseInstance);
+
+               // Flush the response out
+               $responseInstance->flushBuffer();
+       }
+}
+
+// [EOF]
+?>
index c346615239a8d0ff20f23caa832a02d2d0d85b58..db698c2a91a598bdc848d9da1552c590685144a3 100644 (file)
@@ -107,7 +107,7 @@ class UserAuthFilter extends BaseFilter implements Filterable {
                } // END - if
 
                // Now, try to get a user or guest instance
-               if ($authLogin == $this->getConfigInstance()->readConfig('guest_login_username')) {
+               if ($authLogin == $this->getConfigInstance()->readConfig('guest_login_user')) {
                        // Guest login!
                        $userInstance = Guest::createGuestByUserName($authLogin);
                } else {
index b32f0cc4b25dbd54ce42faab76d04d71d453b85e..34def47e4669ef4cd1e5b19bbd1ef6b4799b6ecb 100644 (file)
@@ -64,10 +64,10 @@ class UserNameIsGuestFilter extends BaseFilter implements Filterable {
                $userName = $requestInstance->getRequestElement('username');
 
                // Does the user name match the guest login?
-               if ($userName == $this->getConfigInstance()->readConfig('guest_login_username')) {
+               if ($userName == $this->getConfigInstance()->readConfig('guest_login_user')) {
                        // Then set the password to the configured password
-                       $requestInstance->setRequestElement('pass1', $this->getConfigInstance()->readConfig('guest_login_password'));
-                       $requestInstance->setRequestElement('pass2', $this->getConfigInstance()->readConfig('guest_login_password'));
+                       $requestInstance->setRequestElement('pass1', $this->getConfigInstance()->readConfig('guest_login_passwd'));
+                       $requestInstance->setRequestElement('pass2', $this->getConfigInstance()->readConfig('guest_login_passwd'));
                } // END - if
        }
 }
diff --git a/inc/classes/main/filter/verifier/class_PasswordGuestVerifierFilter.php b/inc/classes/main/filter/verifier/class_PasswordGuestVerifierFilter.php
new file mode 100644 (file)
index 0000000..7e47214
--- /dev/null
@@ -0,0 +1,90 @@
+<?php
+/**
+ * A concrete filter for validating the guest password. This filter may intercept
+ * the filter chain if no password is given or the password is invalid
+ *
+ * @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
+ *
+ * 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 PasswordGuestVerifierFilter extends BaseFilter implements Filterable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set part description
+               $this->setObjectDescription("A filter for password verification");
+
+               // Create unique ID number
+               $this->generateUniqueId();
+       }
+
+       /**
+        * Creates an instance of this filter class
+        *
+        * @return      $filterInstance         An instance of this filter class
+        */
+       public final static function createPasswordGuestVerifierFilter () {
+               // Get a new instance
+               $filterInstance = new PasswordGuestVerifierFilter();
+
+               // Return the instance
+               return $filterInstance;
+       }
+
+       /**
+        * Executes the filter with given request and response objects
+        *
+        * @param       $requestInstance        An instance of a class with an Requestable interface
+        * @param       $responseInstance       An instance of a class with an Responseable interface
+        * @return      void
+        */
+       public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+               // Get password
+               $password = $requestInstance->getRequestElement('passwd');
+
+               // Is the password still not set?
+               if (is_null($password)) {
+                       // Not found in form so stop the filtering process
+                       $requestInstance->requestIsValid(false);
+
+                       // Add a message to the response
+                       $responseInstance->addFatalMessage('password_unset');
+
+                       // Abort here
+                       return false;
+               } elseif (empty($password)) {
+                       // Password is empty
+                       $requestInstance->requestIsValid(false);
+
+                       // Add a message to the response
+                       $responseInstance->addFatalMessage('password_empty');
+
+                       // Abort here
+                       return false;
+               }
+       }
+}
+
+// [EOF]
+?>
diff --git a/inc/classes/main/filter/verifier/class_UserGuestVerifierFilter.php b/inc/classes/main/filter/verifier/class_UserGuestVerifierFilter.php
new file mode 100644 (file)
index 0000000..957407a
--- /dev/null
@@ -0,0 +1,148 @@
+<?php
+/**
+ * A concrete filter for verfying the guest username. This filter may intercept the
+ * filter chain if no username is given or if the supplied username has an
+ * invalid form. It could also intercept the filter chain if the username was
+ * not found.
+ *
+ * @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
+ *
+ * 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 UserGuestVerifierFilter extends BaseFilter implements Filterable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set part description
+               $this->setObjectDescription("A filter for username verification");
+
+               // Create unique ID number
+               $this->generateUniqueId();
+       }
+
+       /**
+        * Creates an instance of this filter class
+        *
+        * @return      $filterInstance         An instance of this filter class
+        */
+       public final static function createUserGuestVerifierFilter () {
+               // Get a new instance
+               $filterInstance = new UserGuestVerifierFilter();
+
+               // Return the instance
+               return $filterInstance;
+       }
+
+       /**
+        * Executes the filter with given request and response objects
+        *
+        * @param       $requestInstance        An instance of a class with an Requestable interface
+        * @param       $responseInstance       An instance of a class with an Responseable interface
+        * @return      void
+        */
+       public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+               // Get username from request
+               $userName = $requestInstance->getRequestElement('user');
+
+               // Is the username set?
+               if (is_null($userName)) {
+                       // Not found in form so stop the filtering process
+                       $requestInstance->requestIsValid(false);
+
+                       // Add a message to the response
+                       $responseInstance->addFatalMessage('username_unset');
+
+                       // Abort here
+                       return false;
+               } elseif (empty($userName)) {
+                       // Empty field!
+                       $requestInstance->requestIsValid(false);
+
+                       // Add a message to the response
+                       $responseInstance->addFatalMessage('username_empty');
+
+                       // Abort here
+                       return false;
+               } elseif (!$this->ifUserGuestIsTaken($userName)) {
+                       // Username is already taken
+                       $requestInstance->requestIsValid(false);
+
+                       // Add a message to the response
+                       $responseInstance->addFatalMessage('username_not_found');
+
+                       // Abort here
+                       return false;
+               }
+
+               // Set the element for compatiblity reasons
+               $requestInstance->setRequestElement('username', $userName);
+       }
+
+       /**
+        * Check wether the username as already been taken
+        *
+        * @param       $userName               Username to check for existence
+        * @return      $alreadyTaken   Wether the username has been taken
+        */
+       private function ifUserGuestIsTaken ($userName) {
+               // Default is already taken
+               $alreadyTaken = true;
+
+               // Initialize instance
+               $userInstance = null;
+
+               // Get a registry instance
+               $registry = Registry::getRegistry();
+
+               // Is the user already there?
+               if ($registry->instanceExists('user')) {
+                       // Use the instance for checking for the email
+                       $userInstance = $registry->getInstance('user');
+                       $userInstance->setUserGuest($userName);
+               } else {
+                       // If this instance is created then the username *does* exist
+                       try {
+                               // Get a new instance
+                               $userInstance = call_user_func_array(array($this->getConfigInstance()->readConfig('guest_class'), "createGuestByUsername"), array($userName));
+
+                               // Remember this user instance in our registry for later usage
+                               $registry->addInstance('user', $userInstance);
+                       } catch (UsernameMissingException $e) {
+                               // User was not found
+                       }
+               }
+
+               // Does the username exist?
+               if ((is_null($userInstance)) || (!$userInstance->ifUsernameExists())) {
+                       // This username is still available
+                       $alreadyTaken = false;
+               }
+
+               // Return the result
+               return $alreadyTaken;
+       }
+}
+
+// [EOF]
+?>
index d3189691d361ca3ef2c12820e95d319fc96cddf6..bcdf4920d874e66cd9a8cf308ffd10a001c5ef32 100644 (file)
@@ -252,9 +252,11 @@ class HttpResponse extends BaseFrameworkSystem implements Responseable {
         * @todo        this will send only one cookie out, the first one.
         */
        public function addCookie ($cookieName, $cookieValue, $encrypted = false, $expires = null) {
+               //* DEBUG: */ echo $cookieName."=".$cookieValue."<br />\n";
                // Are headers already sent?
                if (headers_sent()) {
                        // Throw an exception here
+                       //* DEBUG: */ return;
                        throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT);
                } // END - if
 
index a23d6855caecc5aef0cae2af20008cac093b77c6..03afd0abf97618110ff5150f449dff261714dc4c 100644 (file)
@@ -188,15 +188,21 @@ $cfg->setConfigEntry('password_validator_class', "PasswordValidatorFilter");
 // CFG: RULES-ACCEPTED-CLASS
 $cfg->setConfigEntry('rules_accepted_class', "RulesAcceptedFilter");
 
-// CFG: USERNAME-VERIFIER
+// CFG: USERNAME-VERIFIER-CLASS
 $cfg->setConfigEntry('username_verifier_class', "UserNameVerifierFilter");
 
+// CFG: USER-GUEST-VERIFIER-CLASS
+$cfg->setConfigEntry('user_guest_verifier_class', "UserGuestVerifierFilter");
+
 // CFG: EMAIL-VERIFIER
 $cfg->setConfigEntry('email_verifier_class', "EmailVerifierFilter");
 
 // CFG: PASSWORD-VERIFIER-CLASS
 $cfg->setConfigEntry('password_verifier_class', "PasswordVerifierFilter");
 
+// CFG: PASSWD-GUEST-VERIFIER-CLASS
+$cfg->setConfigEntry('passwd_guest_verifier_class', "PasswordGuestVerifierFilter");
+
 // CFG: EMAIL-CHANGE-CLASS
 $cfg->setConfigEntry('email_change_class', "EmailChangeFilter");
 
index 6d3b99fb9d03187b10c31ecfbf12fbed4ddbf8a7..e6d338085b1c301a99bfb4e94d9af0e40972f52a 100644 (file)
@@ -104,7 +104,7 @@ class FrameworkConfiguration implements Registerable {
                // At least 5.1.0 is required for this!
                if (version_compare(phpversion(), "5.1.0")) {
                        @date_default_timezone_set($zone);
-               }
+               } // END - if
        }
 
        /**
@@ -141,12 +141,12 @@ class FrameworkConfiguration implements Registerable {
                                                // Base path is already added
                                                $fqfn = $inc;
                                        }
-                               }
+                               } // END - if
 
                                // Include them all here
                                require($fqfn);
                        }
-               }
+               } // END - if
        }
 
        /**
@@ -226,7 +226,7 @@ class FrameworkConfiguration implements Registerable {
                // Debug message
                if ((defined('DEBUG_CONFIG')) || (defined('DEBUG_ALL'))) {
                        echo "[".__METHOD__."] Configuration entry ".$cfgEntry." requested.<br />\n";
-               }
+               } // END - if
 
                // Return the requested value
                return $this->config[$cfgEntry];
@@ -249,7 +249,7 @@ class FrameworkConfiguration implements Registerable {
                if (empty($cfgEntry)) {
                        // Entry is empty
                        throw new ConfigEntryIsEmptyException($this, self::EXCEPTION_CONFIG_ENTRY_IS_EMPTY);
-               }
+               } // END - if
 
                // Set the configuration value
                $this->config[$cfgEntry] = $cfgValue;