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
$this->setObjectDescription("Generic user class");
// Create unique ID number
- $this->createUniqueID();
+ $this->generateUniqueId();
// Clean up a little
$this->removeNumberFormaters();
$userInstance = new User();
// Set the username
- $userInstance->setUsername($userName);
+ $userInstance->setUserName($userName);
// Check if the username exists
if (!$userInstance->ifUsernameExists()) {
* @param $userName The username to set
* @return void
*/
- protected final function setUsername ($userName) {
- $this->UserName = $userName;
+ public final function setUserName ($userName) {
+ $this->userName = $userName;
}
/**
* @return void
*/
protected final function setEmail ($email) {
- $this->userName = $email;
+ $this->email = $email;
}
/**
* @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');
$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]