]> git.mxchange.org Git - shipsimu.git/commitdiff
Guest login basicly supported (not finished yet!)
authorRoland Häder <roland@mxchange.org>
Thu, 19 Jun 2008 18:11:57 +0000 (18:11 +0000)
committerRoland Häder <roland@mxchange.org>
Thu, 19 Jun 2008 18:11:57 +0000 (18:11 +0000)
13 files changed:
.gitattributes
application/ship-simu/config.php
application/ship-simu/main/commands/web/class_WebShipsimuGuestLoginCommand.php [new file with mode: 0644]
application/ship-simu/main/commands/web/class_WebShipsimuRegisterCommand.php
application/ship-simu/main/login/class_ShipSimuGuestLogin.php [new file with mode: 0644]
application/ship-simu/main/login/class_ShipSimuUserLogin.php
application/ship-simu/main/registration/class_ShipSimuRegistration.php
application/ship-simu/templates/de/code/login_failed.ctp
application/ship-simu/templates/de/code/login_form.ctp
inc/classes/main/filter/guest/.htaccess [new file with mode: 0644]
inc/classes/main/filter/guest/class_UserNameIsGuestFilter.php [new file with mode: 0644]
inc/classes/main/user/class_Guest.php [new file with mode: 0644]
inc/config.php

index 84cffb0d68efb46ff11e3c3baa1b8b61cb14a764..02a4bcfcfe7351877dfd4a52ba3a928789ddf622 100644 (file)
@@ -64,6 +64,7 @@ application/ship-simu/main/class_Merchant.php -text
 application/ship-simu/main/class_WorksContract.php -text
 application/ship-simu/main/commands/.htaccess -text
 application/ship-simu/main/commands/web/.htaccess -text
+application/ship-simu/main/commands/web/class_WebShipsimuGuestLoginCommand.php -text
 application/ship-simu/main/commands/web/class_WebShipsimuRegisterCommand.php -text
 application/ship-simu/main/commands/web/class_WebShipsimuUserLoginCommand.php -text
 application/ship-simu/main/companies/.htaccess -text
@@ -87,6 +88,7 @@ application/ship-simu/main/drives/motor/class_Motor.php -text
 application/ship-simu/main/factories/.htaccess -text
 application/ship-simu/main/factories/class_ShipSimuWebNewsFactory.php -text
 application/ship-simu/main/login/.htaccess -text
+application/ship-simu/main/login/class_ShipSimuGuestLogin.php -text
 application/ship-simu/main/login/class_ShipSimuUserLogin.php -text
 application/ship-simu/main/login/helper/.htaccess -text
 application/ship-simu/main/login/helper/class_ShipSimuLoginHelper.php -text
@@ -398,6 +400,8 @@ inc/classes/main/filter/class_AbstractFilterDecorator.php -text
 inc/classes/main/filter/class_BaseFilter.php -text
 inc/classes/main/filter/class_FilterChain.php -text
 inc/classes/main/filter/decorator/.htaccess -text
+inc/classes/main/filter/guest/.htaccess -text
+inc/classes/main/filter/guest/class_UserNameIsGuestFilter.php -text
 inc/classes/main/filter/news/.htaccess -text
 inc/classes/main/filter/news/class_NewsDownloadFilter.php -text
 inc/classes/main/filter/news/class_NewsProcessFilter.php -text
@@ -452,6 +456,7 @@ inc/classes/main/rng/class_RandomNumberGenerator.php -text
 inc/classes/main/template/.htaccess -text
 inc/classes/main/template/class_TemplateEngine.php -text
 inc/classes/main/user/.htaccess -text
+inc/classes/main/user/class_Guest.php -text
 inc/classes/main/user/class_User.php -text
 inc/classes/middleware/.htaccess -text
 inc/classes/middleware/class_BaseMiddleware.php -text
index cba02a1bf1db60e1a9771241dcb1eb58efe3f315..a63a95c12bae480c8fd8977ea535f8f25eab479d 100644 (file)
@@ -70,12 +70,18 @@ $cfg->setConfigEntry('chat_enabled_msn', "Y");
 // CFG: USER-REGISTRATION
 $cfg->setConfigEntry('user_registration_class', "ShipSimuRegistration");
 
-// CFG: LOGIN-USER
+// CFG: USER-LOGIN-CLASS
 $cfg->setConfigEntry('user_login_class', "ShipSimuUserLogin");
 
+// CFG: GUEST-LOGIN-CLASS
+$cfg->setConfigEntry('guest_login_class', "ShipSimuGuestLogin");
+
 // CFG: USER-STATUS-REGISTER
 $cfg->setConfigEntry('user_status_register', "UNCONFIRMED");
 
+// CFG: GUEST-STATUS
+$cfg->setConfigEntry('user_status_guest', "GUEST");
+
 // CFG: LOGIN-HELPER
 $cfg->setConfigEntry('login_helper_class', "ShipSimuLoginHelper");
 
diff --git a/application/ship-simu/main/commands/web/class_WebShipsimuGuestLoginCommand.php b/application/ship-simu/main/commands/web/class_WebShipsimuGuestLoginCommand.php
new file mode 100644 (file)
index 0000000..960ba39
--- /dev/null
@@ -0,0 +1,119 @@
+<?php
+/**
+ * A command for guest logins
+ *
+ * @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 WebShipsimuGuestLoginCommand extends BaseCommand implements Commandable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set part description
+               $this->setObjectDescription("User login handling command for Ship-Simu");
+
+               // Create unique ID number
+               $this->generateUniqueId();
+
+               // Clean up a little
+               $this->removeNumberFormaters();
+               $this->removeSystemArray();
+       }
+
+       /**
+        * Creates an instance of this command and sets the resolver instance
+        *
+        * @param       $resolverInstance       An instance of a command resolver
+        * @return      $commandInstance        The created command instance
+        */
+       public final static function createWebShipsimuGuestLoginCommand (CommandResolver $resolverInstance) {
+               // Get a new instance
+               $commandInstance = new WebShipsimuGuestLoginCommand();
+
+               // Set the resolver instance
+               $commandInstance->setResolverInstance($resolverInstance);
+
+               // Get the controller instance from the resolver (breaks MVC pattern again)
+               $controllerInstance = $resolverInstance->getControllerInstance();
+
+               switch ($commandInstance->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;
+               }
+
+               /* @TODO Add more filters */
+               $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('password_verifier_class'));
+
+               // Return the prepared instance
+               return $commandInstance;
+       }
+
+       /**
+        * Executes the command 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) {
+               // First get a GuestLogin instance
+               $loginInstance = ObjectFactory::createObjectByConfiguredName('guest_login_class');
+
+               // First set request and response instance
+               $loginInstance->setRequestInstance($requestInstance);
+
+               // Encrypt the password
+               $loginInstance->encryptPassword('pass');
+
+               // Do the login here
+               $loginInstance->doLogin($requestInstance, $responseInstance);
+
+               // Was the login fine? Then redirect here
+               if ($loginInstance->ifLoginWasSuccessfull()) {
+                       // Try to redirect here
+                       try {
+                               $responseInstance->redirectToConfiguredUrl('app_login_url');
+                       } catch (FrameworkException $e) {
+                               // Something went wrong here!
+                               $responseInstance->addFatalMessage($e->getMessage());
+                       }
+               } else {
+                       // Attach error message to the response
+                       $responseInstance->addFatalMessage('failed_user_login');
+               }
+       }
+}
+
+// [EOF]
+?>
index f7e50f7870ae8f734c0912780566bcd8041f6205..035991df0644fb10211f46eb68c8bf4ed83f45c5 100644 (file)
@@ -61,6 +61,7 @@ class WebShipsimuRegisterCommand extends BaseCommand implements Commandable {
                /* @TODO Add some more pre/post filters to the controller */
                $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('email_validator_class'));
                $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('username_validator_class'));
+               $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('username_is_guest_class'));
                $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('password_validator_class'));
                $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('rules_accepted_class'));
 
diff --git a/application/ship-simu/main/login/class_ShipSimuGuestLogin.php b/application/ship-simu/main/login/class_ShipSimuGuestLogin.php
new file mode 100644 (file)
index 0000000..198f74c
--- /dev/null
@@ -0,0 +1,172 @@
+<?php
+/**
+ * A special guest login class for Ship-Simu
+ *
+ * @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 ShipSimuGuestLogin extends BaseFrameworkSystem implements LoginableUser {
+       /**
+        * The hashed password
+        */
+       private $hashedPassword = "";
+
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set part description
+               $this->setObjectDescription("Guest 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 createShipSimuGuestLogin () {
+               // Get a new instance
+               $loginInstance = new ShipSimuGuestLogin();
+
+               // 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
+        * @param       $responseInstance       An instance of a Responseable class
+        * @return      void
+        * @throws      UserAuthMethodException If wether username nor email login
+        *                                                                              was detected
+        * @throws      MissingMethodException          If a method was not found in the
+        *                                                                              User class
+        * @throws      UserPasswordMismatchException   If the supplied password did not
+        *                                                                              match with the stored password
+        */
+       public function doLogin (Requestable $requestInstance, Responseable $responseInstance) {
+               // 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 = "createGuestByUsername";
+                       $data = $requestInstance->getRequestElement('username');
+               } elseif (!is_null($requestInstance->getRequestElement('email'))) {
+                       // Email found!
+                       $method = "createGuestByEmail";
+                       $data = $requestInstance->getRequestElement('email');
+               }
+
+               // Is a method detected?
+               if (is_null($method)) {
+                       // Then abort here
+                       throw new UserAuthMethodException($this, self::EXCEPTION_MISSING_METHOD);
+               } elseif (!method_exists($this->getConfigInstance()->readConfig('guest_class'), $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($this->getConfigInstance()->readConfig('guest_class'), $method), array($data));
+
+                       // Remember this new instance in registry
+                       Registry::getRegistry()->addInstance($userInstance);
+               } // END - if
+
+               // Is the password correct?
+               if (!$userInstance->ifPasswordHashMatches($requestInstance)) {
+                       // Mismatching password
+                       throw new UserPasswordMismatchException(array($this, $userInstance), User::EXCEPTION_USER_PASS_MISMATCH);
+               } // END - if
+
+               // Now do the real login. This can be cookie- or session-based login
+               // which depends on the admins setting then on the user's taste.
+               // 1) Get a login helper instance
+               $helperInstance = ObjectFactory::createObjectByConfiguredName('login_helper_class', array($requestInstance));
+
+               // 2) Execute the login. This will now login...
+               $helperInstance->executeLogin($responseInstance);
+       }
+
+       /**
+        * Determines wether the login was fine. This is done by checking if the 'login' instance is in registry
+        *
+        * @return      $loginDone      Wether the login was fine or not
+        */
+       public function ifLoginWasSuccessfull () {
+               // Is the registry key there?
+               $loginDone = (Registry::getRegistry()->getInstance('login') instanceof Registerable);
+
+               // Return the result
+               return $loginDone;
+       }
+
+       /**
+        * Encrypt the given request key or throw an exception if the key was not
+        * found in the request
+        *
+        * @param       $requestKey             Key in request class
+        * @return      void
+        */
+       public function encryptPassword ($requestKey) {
+               // Check if the password is found in the request
+               if ($this->getRequestInstance()->isRequestElementSet($requestKey)) {
+                       // So encrypt the password and store it for later usage in
+                       // the request:
+
+                       // Get the plain password
+                       $plainPassword = $this->getRequestInstance()->getRequestElement($requestKey);
+
+                       // Get user instance
+                       $userInstance = Registry::getRegistry()->getInstance('user');
+
+                       // Get a crypto helper and hash the password
+                       $this->hashedPassword = ObjectFactory::createObjectByConfiguredName('crypto_class')->hashPassword($plainPassword, $userInstance->getPasswordHash());
+
+                       // Store the hash back in the request
+                       $this->getRequestInstance()->setRequestElement('pass_hash', $this->hashedPassword);
+               } // END - if
+       }
+}
+
+// [EOF]
+?>
index 1f62ded44872b635a679bc03b8acde9156a65ce2..5037bd8c658c31f33c36ea09463bda17e0dbfd9e 100644 (file)
@@ -118,6 +118,10 @@ class ShipSimuUserLogin extends BaseFrameworkSystem implements LoginableUser {
                        throw new UserPasswordMismatchException(array($this, $userInstance), User::EXCEPTION_USER_PASS_MISMATCH);
                } // END - if
 
+               /* @TODO We need to add something here which will make more than one */
+               /* @TODO guest logins, users who are online but based on the same */
+               /* @TODO user account. */
+
                // Now do the real login. This can be cookie- or session-based login
                // which depends on the admins setting then on the user's taste.
                // 1) Get a login helper instance
index aae55e7f86a83325d82f1f4795d6421f95680f32..eac7106f6a4944d74be64a6ea2f446fa60d772ee 100644 (file)
@@ -156,6 +156,9 @@ class ShipSimuRegistration extends BaseRegistration {
         * @return      void
         */
        public function addElementsToDataSet (StoreableCriteria $criteriaInstance) {
+               // Default is user account!
+               $configEntry = 'user_status_register';
+
                // Add a lot elements to the dataset criteria
                foreach ($this->criteriaElements as $alias=>$element) {
                        // Do we have an alias?
@@ -166,13 +169,19 @@ class ShipSimuRegistration extends BaseRegistration {
                                // No, default entry
                                $criteriaInstance->addCriteria($element, $this->getRequestInstance()->getRequestElement($element));
                        }
+
+                       // Is this a guest account?
+                       if ((($element == "username") || ($alias == "username")) && ($this->getRequestInstance()->getRequestElement($element) == $this->getConfigInstance()->readConfig('guest_login_username'))) {
+                               // Yes, then set the config entry to guest status
+                               $configEntry = 'user_status_guest';
+                       } // END - if
                } // END - foreach
 
                // Mark the username as unique key
                $criteriaInstance->setUniqueKey('username');
 
                // Add account status as configured
-               $criteriaInstance->addConfiguredCriteria('user_status', 'user_status_register');
+               $criteriaInstance->addConfiguredCriteria('user_status', $configEntry);
        }
 }
 
index e823120a2ab206c22386703fc58f720af77f5522..4d9d42e26a32ab9f76b55207f01c132f506a0f84 100644 (file)
@@ -19,6 +19,9 @@
 </div>
 
 <div id="content_footer">
-       [<a href="$config[base_url]/index.php?app=ship-simu&amp;page=login">Login erneut probieren</a>]
+       <div id="login_retry">
+               [<a href="$config[base_url]/index.php?app=ship-simu&amp;page=login">Login erneut probieren</a>]
+       </div>
+
        Vielen Dank f&uuml;r deine Mitarbeit! :-)
 </div>
index afd2941d8369f75695dfcd7b0ebd938f91f15601..d890f183126d92e176cdb6fda7ca381a1d00f35c 100644 (file)
@@ -48,7 +48,7 @@ if ($helper->ifGuestLoginAllowed()) {
        // Neue Helper-Instanz holen
        $helper = WebFormHelper::createWebFormHelper($this, "shipsimu_guest_login");
        $helper->addInputHiddenField("username", $this->getConfigInstance()->readConfig('guest_login_username'));
-       $helper->addInputHiddenField("password", $this->getConfigInstance()->readConfig('guest_login_password'));
+       $helper->addInputHiddenField("pass", $this->getConfigInstance()->readConfig('guest_login_password'));
        $helper->addFormGroup("buttons", "Gastlogins sind in der Funkionsweise eingeschr&auml;nkt. Mehr dazu unter &quot;Gastlogin&quot;.");
        $helper->addInputSubmitButton("Als Gast einloggen");
        $helper->addFormTag();
diff --git a/inc/classes/main/filter/guest/.htaccess b/inc/classes/main/filter/guest/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/inc/classes/main/filter/guest/class_UserNameIsGuestFilter.php b/inc/classes/main/filter/guest/class_UserNameIsGuestFilter.php
new file mode 100644 (file)
index 0000000..b32f0cc
--- /dev/null
@@ -0,0 +1,76 @@
+<?php
+/**
+ * A filter for checking if the username "guest" has been choosen as configured.
+ * If so the password will be set to the configured password.
+ *
+ * @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 UserNameIsGuestFilter 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 checking if username is the reserved guest login");
+
+               // 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 createUserNameIsGuestFilter () {
+               // Get a new instance
+               $filterInstance = new UserNameIsGuestFilter();
+
+               // 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('username');
+
+               // Does the user name match the guest login?
+               if ($userName == $this->getConfigInstance()->readConfig('guest_login_username')) {
+                       // 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'));
+               } // END - if
+       }
+}
+
+// [EOF]
+?>
diff --git a/inc/classes/main/user/class_Guest.php b/inc/classes/main/user/class_Guest.php
new file mode 100644 (file)
index 0000000..c5ea225
--- /dev/null
@@ -0,0 +1,352 @@
+<?php
+/**
+ * A generic class for handling guests
+ *
+ * @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 Guest extends BaseFrameworkSystem implements ManageableUser, Registerable {
+       /**
+        * Instance of the database result
+        */
+       private $resultInstance = null;
+
+       /**
+        * Username of current user
+        */
+       private $userName = "";
+
+       /**
+        * Email of current user
+        */
+       private $email = "";
+
+       // Exceptions
+       const EXCEPTION_USERNAME_NOT_FOUND   = 0x060;
+       const EXCEPTION_USER_EMAIL_NOT_FOUND = 0x061;
+       const EXCEPTION_USER_PASS_MISMATCH   = 0x062;
+
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct ($class = "") {
+               // Is the class name empty? Then this is not a specialized user class
+               if (empty($class)) $class = __CLASS__;
+
+               // Call parent constructor
+               parent::__construct($class);
+
+               // Set part description
+               $this->setObjectDescription("Generic user class");
+
+               // Create unique ID number
+               $this->generateUniqueId();
+
+               // Clean up a little
+               $this->removeNumberFormaters();
+               $this->removeSystemArray();
+       }
+
+       /**
+        * Creates an instance of this user class by a provided username. This
+        * factory method will check if the username is already taken and if not
+        * so it will throw an exception.
+        *
+        * @param       $userName               Username we need a class instance for
+        * @return      $userInstance   An instance of this user class
+        * @throws      UsernameMissingException        If the username does not exist
+        */
+       public final static function createGuestByUsername ($userName) {
+               // Get a new instance
+               $userInstance = new Guest();
+
+               // Set the username
+               $userInstance->setUserName($userName);
+
+               // Check if the username exists
+               if (!$userInstance->ifUsernameExists()) {
+                       // Throw an exception here
+                       throw new UsernameMissingException(array($userInstance, $userName), self::EXCEPTION_USERNAME_NOT_FOUND);
+               }
+
+               // Return the instance
+               return $userInstance;
+       }
+
+       /**
+        * Creates an instance of this user class by a provided email address. This
+        * factory method will not check if the email address is there.
+        *
+        * @param       $email                  Email address of the user
+        * @return      $userInstance   An instance of this user class
+        */
+       public final static function createGuestByEmail ($email) {
+               // Get a new instance
+               $userInstance = new User();
+
+               // Set the username
+               $userInstance->setEmail($email);
+
+               // Return the instance
+               return $userInstance;
+       }
+
+       /**
+        * "Getter" for databse entry
+        *
+        * @return      $entry  An array with database entries
+        * @throws      NullPointerException    If the database result is not found
+        * @throws      InvalidDatabaseResultException  If the database result is invalid
+        */
+       private function getDatabaseEntry () {
+               // Is there an instance?
+               if (is_null($this->resultInstance)) {
+                       // Throw new exception
+                       throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+               } // END - if
+
+               // Rewind it
+               $this->resultInstance->rewind();
+
+               // Do we have an entry?
+               if (!$this->resultInstance->valid()) {
+                       throw new InvalidDatabaseResultException(array($this, $this->resultInstance), DatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
+               } // END - if
+
+               // Get next entry
+               $this->resultInstance->next();
+
+               // Fetch it
+               $entry = $this->resultInstance->current();
+
+               // And return it
+               return $entry;
+       }
+
+       /**
+        * Setter for username
+        *
+        * @param       $userName       The username to set
+        * @return      void
+        */
+       public final function setUserName ($userName) {
+               $this->userName = $userName;
+       }
+
+       /**
+        * Setter for email
+        *
+        * @param       $email  The email to set
+        * @return      void
+        */
+       protected final function setEmail ($email) {
+               $this->email = $email;
+       }
+
+       /**
+        * Getter for username
+        *
+        * @return      $userName       The username to get
+        */
+       public final function getUsername () {
+               return $this->userName;
+       }
+
+       /**
+        * Getter for email
+        *
+        * @return      $email  The email to get
+        */
+       public final function getEmail () {
+               return $this->email;
+       }
+
+       /**
+        * Determines wether the username exists or not
+        *
+        * @return      $exists         Wether the username exists
+        */
+       public function ifUsernameExists () {
+               // By default the username does not exist
+               $exists = false;
+
+               // Is a previous result there?
+               if (is_null($this->resultInstance)) {
+                       // Get a UserDatabaseWrapper instance
+                       $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
+
+                       // Create a search criteria
+                       $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+                       // Add the username as a criteria and set limit to one entry
+                       $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUsername());
+                       $criteriaInstance->setLimit(1);
+
+                       // Get a search result
+                       $this->resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+               } else {
+                       // Rewind it
+                       $this->resultInstance->rewind();
+               }
+
+               // Search for it
+               if ($this->resultInstance->next()) {
+                       // Entry found
+                       $exists = true;
+               } // END - if
+
+               // Return the status
+               return $exists;
+       }
+
+       /**
+        * Determines wether the email exists or not
+        *
+        * @return      $exists         Wether the email exists
+        */
+       public function ifEmailAddressExists () {
+               // By default the email does not exist
+               $exists = false;
+
+               // Is a previous result there?
+               if (is_null($this->resultInstance)) {
+                       // Get a UserDatabaseWrapper instance
+                       $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
+
+                       // Create a search criteria
+                       $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+                       // Add the username as a criteria and set limit to one entry
+                       $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_EMAIL, $this->getEmail());
+                       $criteriaInstance->setLimit(1);
+
+                       // Get a search resultInstance
+                       $this->resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+               } else {
+                       // Rewind it
+                       $this->resultInstance->rewind();
+               }
+
+               // Search for it
+               if ($this->resultInstance->next()) {
+                       // Entry found
+                       $exists = true;
+               } // END - if
+
+               // Return the status
+               return $exists;
+       }
+
+       /**
+        * Checks if the supplied password hash in request matches with the stored
+        * in database.
+        *
+        * @param       $requestInstance        A requestable class instance
+        * @return      $matches                        Wether the supplied password hash matches
+        */
+       public function ifPasswordHashMatches (Requestable $requestInstance) {
+               // By default nothing matches... ;)
+               $matches = false;
+
+               // Get a UserDatabaseWrapper instance
+               $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
+
+               // Create a search criteria
+               $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+               // Add the username as a criteria and set limit to one entry
+               $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
+               $criteriaInstance->setLimit(1);
+
+               // Get a search resultInstance
+               $this->resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+
+               // Search for it
+               if ($this->resultInstance->next()) {
+                       // Get the current entry (can only be one!)
+                       $entry = $this->resultInstance->current();
+
+                       // So does the hashes match?
+                       //* DEBUG: */ echo $requestInstance->getRequestElement('pass_hash')."/".$entry['pass_hash'];
+                       $matches = ($requestInstance->getRequestElement('pass_hash') === $entry['pass_hash']);
+               } // END - if
+
+               // Return the status
+               return $matches;
+       }
+
+       /**
+        * Adds data for later complete update
+        *
+        * @param       $column         Column we want to update
+        * @param       $value          New value to store in database
+        * @return      void
+        */
+       public function addUpdateData ($column, $value) {
+               $this->partialStub("Column={$column}, value={$value}");
+       }
+
+       /**
+        * "Getter" for user's password hash
+        *
+        * @return      $passHash       User's password hash from database result
+        */
+       public function getPasswordHash () {
+               // Default is missing password hash
+               $passHash = null;
+
+               // Get a database entry
+               $entry = $this->getDatabaseEntry();
+
+               // Is the password hash there?
+               if (isset($entry['pass_hash'])) {
+                       // Get it
+                       $passHash = $entry['pass_hash'];
+               }
+
+               // And return the hash
+               return $passHash;
+       }
+
+       /**
+        * Updates the last activity timestamp and last performed action in the
+        * database result. You should call flushUpdates() to flush these updates
+        * to the database layer.
+        *
+        * @param       $requestInstance        A requestable class instance
+        * @return      void
+        */
+       public function updateLastActivity (Requestable $requestInstance) {
+               // No activity will be logged for guest accounts
+       }
+
+       /**
+        * Flushs all updated entries to the database layer
+        *
+        * @return      void
+        */
+       public function flushUpdates () {
+               // No updates will be flushed to database!
+       }
+}
+
+// [EOF]
+?>
index 08052ad4c4da32e3a9f45de3888cb5330a959297..321d5133687428123336bb5d1661c0531dc85b35 100644 (file)
@@ -179,6 +179,9 @@ $cfg->setConfigEntry('email_validator_class', "EmailValidatorFilter");
 // CFG: USERNAME-VALIDATOR
 $cfg->setConfigEntry('username_validator_class', "UserNameValidatorFilter");
 
+// CFG: USERNAME-IS-GUEST
+$cfg->setConfigEntry('username_is_guest_class', "UserNameIsGuestFilter");
+
 // CFG: PASSWORD-VALIDATOR
 $cfg->setConfigEntry('password_validator_class', "PasswordValidatorFilter");
 
@@ -233,6 +236,9 @@ $cfg->setConfigEntry('post_registration_class', "LoginAfterRegistrationAction");
 // CFG: USER-CLASS
 $cfg->setConfigEntry('user_class', "User");
 
+// CFG: GUEST-CLASS
+$cfg->setConfigEntry('guest_class', "Guest");
+
 // CFG: COOKIE-EXPIRE
 $cfg->setConfigEntry('cookie_expire', (60*60*2)); // Two hours!