]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/user/class_User.php
Results are now searchable and iterateable, insertDataSet renamed to queryInsertDataS...
[shipsimu.git] / inc / classes / main / user / class_User.php
index 564d0ecf21e652ccf63c3ed54fbf4d1a5631d212..302c117d73d475c0fdb4d6129b2fbd7bdc60a5d2 100644 (file)
@@ -33,7 +33,9 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable {
        private $email = "";
 
        // Exceptions
-       const EXCEPTION_USERNAME_NOT_FOUND = 0xd00;
+       const EXCEPTION_USERNAME_NOT_FOUND   = 0xd00;
+       const EXCEPTION_USER_EMAIL_NOT_FOUND = 0xd01;
+       const EXCEPTION_USER_PASS_MISMATCH   = 0xd02;
 
        /**
         * Protected constructor
@@ -51,7 +53,7 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable {
                $this->setObjectDescription("Generic user class");
 
                // Create unique ID number
-               $this->createUniqueID();
+               $this->generateUniqueId();
 
                // Clean up a little
                $this->removeNumberFormaters();
@@ -72,7 +74,7 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable {
                $userInstance = new User();
 
                // Set the username
-               $userInstance->setUsername($userName);
+               $userInstance->setUserName($userName);
 
                // Check if the username exists
                if (!$userInstance->ifUsernameExists()) {
@@ -108,8 +110,8 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable {
         * @param       $userName       The username to set
         * @return      void
         */
-       protected final function setUsername ($userName) {
-               $this->UserName = $userName;
+       public final function setUserName ($userName) {
+               $this->userName = $userName;
        }
 
        /**
@@ -119,7 +121,7 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable {
         * @return      void
         */
        protected final function setEmail ($email) {
-               $this->userName = $email;
+               $this->email = $email;
        }
 
        /**
@@ -146,11 +148,11 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable {
         * @return      $exists         Wether the username exists
         */
        public function ifUsernameExists () {
-               // By default the username does exist
-               $exists = true;
+               // By default the username does not exist
+               $exists = false;
 
                // Get a UserDatabaseWrapper instance
-               $wrapperInstance = UserDatabaseWrapper::createUserDatabaseWrapper();
+               $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper');
 
                // Create a search criteria
                $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria');
@@ -163,14 +165,94 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable {
                $result = $wrapperInstance->doSelectByCriteria($criteriaInstance);
 
                // Search for it
-               if (!$result->next()) {
-                       // Entry not found
-                       $exists = false;
+               if ($result->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;
+
+               // Get a UserDatabaseWrapper instance
+               $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper');
+
+               // Create a search criteria
+               $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria');
+
+               // 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 result
+               $result = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+
+               // Search for it
+               if ($result->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');
+
+               // Create a search criteria
+               $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria');
+
+               // 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
+               $result = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+
+               // Search for it
+               if ($result->next()) {
+                       // Get the current entry (can only be one!)
+                       $entry = $result->current();
+
+                       // So does the hashes match?
+                       $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}");
+       }
 }
 
 // [EOF]