Code sync from ship-simu code (all class config entries must end with _class!)
[mailer.git] / inc / classes / main / user / class_User.php
index 25e2cc3ffd1e5cdd2745da5d444425878062355e..cc9c44348058bd2e9645030a5d2950a22554955e 100644 (file)
@@ -33,8 +33,9 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable {
        private $email = "";
 
        // Exceptions
-       const EXCEPTION_USERNAME_NOT_FOUND   = 0xd00;
-       const EXCEPTION_USER_EMAIL_NOT_FOUND = 0xd01;
+       const EXCEPTION_USERNAME_NOT_FOUND   = 0x060;
+       const EXCEPTION_USER_EMAIL_NOT_FOUND = 0x061;
+       const EXCEPTION_USER_PASS_MISMATCH   = 0x062;
 
        /**
         * Protected constructor
@@ -147,14 +148,14 @@ 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 = ObjectFactory::createObjectByConfiguredName('user_db_wrapper');
+               $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
 
                // Create a search criteria
-               $criteriaInstance = ObjectFactory::createObjectByConfiguredName('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());
@@ -164,9 +165,9 @@ 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
@@ -179,14 +180,14 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable {
         * @return      $exists         Wether the email exists
         */
        public function ifEmailAddressExists () {
-               // By default the username does exist
-               $exists = true;
+               // By default the email does not exist
+               $exists = false;
 
                // Get a UserDatabaseWrapper instance
-               $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper');
+               $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
 
                // Create a search criteria
-               $criteriaInstance = ObjectFactory::createObjectByConfiguredName('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());
@@ -196,14 +197,62 @@ 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;
        }
+
+       /**
+        * 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 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]