X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fuser%2Fclass_User.php;h=302c117d73d475c0fdb4d6129b2fbd7bdc60a5d2;hb=fd80d47afc96ae0c0759530800051a0f07eb9c92;hp=25e2cc3ffd1e5cdd2745da5d444425878062355e;hpb=17108ad876ce8da6ac70b2d2393c762b8e9a2513;p=shipsimu.git diff --git a/inc/classes/main/user/class_User.php b/inc/classes/main/user/class_User.php index 25e2cc3..302c117 100644 --- a/inc/classes/main/user/class_User.php +++ b/inc/classes/main/user/class_User.php @@ -35,6 +35,7 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable { // Exceptions const EXCEPTION_USERNAME_NOT_FOUND = 0xd00; const EXCEPTION_USER_EMAIL_NOT_FOUND = 0xd01; + const EXCEPTION_USER_PASS_MISMATCH = 0xd02; /** * Protected constructor @@ -147,8 +148,8 @@ 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'); @@ -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,8 +180,8 @@ 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'); @@ -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'); + + // 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]