X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fuser%2Fclass_BaseUser.php;h=b00a0730f4cfe6b1d4da5cc1057e25730e8f87bf;hb=12dbc1af8f0bc2981711b17c7c955f270c440b35;hp=0a3432de390c06c6729bc4ff4760a5f6009b6071;hpb=c59dccf46c5d0e3b7f2687370b2b15023b1ecdfe;p=hub.git diff --git a/inc/classes/main/user/class_BaseUser.php b/inc/classes/main/user/class_BaseUser.php index 0a3432de3..b00a0730f 100644 --- a/inc/classes/main/user/class_BaseUser.php +++ b/inc/classes/main/user/class_BaseUser.php @@ -32,6 +32,11 @@ class BaseUser extends BaseFrameworkSystem { */ private $userName = ""; + /** + * User id of current user + */ + private $userId = 0; + /** * Email of current user */ @@ -59,26 +64,46 @@ class BaseUser extends BaseFrameworkSystem { * @return void */ public final function setUserName ($userName) { - $this->userName = $userName; + $this->userName = (string) $userName; } /** - * Setter for email + * Getter for username * - * @param $email The email to set + * @return $userName The username to get + */ + public final function getUserName () { + return $this->userName; + } + + /** + * Setter for user id + * + * @param $userId The user id to set * @return void + * @todo Find a way of casting here. "(int)" might destroy the user id > 32766 */ - protected final function setEmail ($email) { - $this->email = $email; + public final function setUserId ($userId) { + $this->userId = $userId; } /** - * Getter for username + * Getter for user id * - * @return $userName The username to get + * @return $userId The user id to get */ - public final function getUsername () { - return $this->userName; + public final function getUserId () { + return $this->userId; + } + + /** + * Setter for email + * + * @param $email The email to set + * @return void + */ + protected final function setEmail ($email) { + $this->email = (string) $email; } /** @@ -108,15 +133,21 @@ class BaseUser extends BaseFrameworkSystem { $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->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName()); $criteriaInstance->setLimit(1); // Get a search result - $this->setResultInstance($wrapperInstance->doSelectByCriteria($criteriaInstance)); - } else { - // Rewind it - $this->getResultInstance()->rewind(); - } + $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance); + + // Set the index "solver" + $resultInstance->solveResultIndex(UserDatabaseWrapper::DB_COLUMN_USERID, $wrapperInstance, array($this, 'setUserId')); + + // And finally set it + $this->setResultInstance($resultInstance); + } // END - if + + // Rewind it + $this->getResultInstance()->rewind(); // Search for it if ($this->getResultInstance()->next()) { @@ -149,12 +180,18 @@ class BaseUser extends BaseFrameworkSystem { $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_EMAIL, $this->getEmail()); $criteriaInstance->setLimit(1); - // Get a search resultInstance - $this->setResultInstance($wrapperInstance->doSelectByCriteria($criteriaInstance)); - } else { - // Rewind it - $this->getResultInstance()->rewind(); - } + // Get a search result + $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance); + + // Set the index "solver" + $resultInstance->solveResultIndex(UserDatabaseWrapper::DB_COLUMN_USERID, $wrapperInstance, array($this, 'setUserId')); + + // And finally set it + $this->setResultInstance($resultInstance); + } // END - if + + // Rewind it + $this->getResultInstance()->rewind(); // Search for it if ($this->getResultInstance()->next()) { @@ -176,8 +213,8 @@ class BaseUser extends BaseFrameworkSystem { } /** - * Checks if the supplied password hash in request matches with the stored - * in database. + * Checks if 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 @@ -186,27 +223,36 @@ class BaseUser extends BaseFrameworkSystem { // By default nothing matches... ;) $matches = false; - // Get a UserDatabaseWrapper instance - $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class'); + // Is a previous result there? + if (is_null($this->getResultInstance())) { + // 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 + $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance); - // Create a search criteria - $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); + // Set the index "solver" + $resultInstance->solveResultIndex(UserDatabaseWrapper::DB_COLUMN_USERID, $wrapperInstance, array($this, 'setUserId')); - // Add the username as a criteria and set limit to one entry - $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName()); - $criteriaInstance->setLimit(1); + // And finally set it + $this->setResultInstance($resultInstance); + } // END - if - // Get a search resultInstance - $this->setResultInstance($wrapperInstance->doSelectByCriteria($criteriaInstance)); + // Rewind it + $this->getResultInstance()->rewind(); // Search for it - if ($this->getResultInstance()->next()) { - // Get the current entry (can only be one!) - $entry = $this->getResultInstance()->current(); - + if ($this->getResultInstance()->find('pass_hash')) { // So does the hashes match? //* DEBUG: */ echo $requestInstance->getRequestElement('pass_hash')."/".$entry['pass_hash']; - $matches = ($requestInstance->getRequestElement('pass_hash') === $entry['pass_hash']); + $matches = ($requestInstance->getRequestElement('pass_hash') === $this->getResultInstance()->getFoundValue()); } // END - if // Return the status