X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fuser%2Fclass_User.php;h=f2ee7df52be1fb3268d4757fbc656e6c173bf94b;hb=12dbc1af8f0bc2981711b17c7c955f270c440b35;hp=280adec1600d86e43d65fc161b223fbe348da7eb;hpb=1f1f351e726dae5d4cd25b46639c2fcaa9e38661;p=hub.git diff --git a/inc/classes/main/user/class_User.php b/inc/classes/main/user/class_User.php index 280adec16..f2ee7df52 100644 --- a/inc/classes/main/user/class_User.php +++ b/inc/classes/main/user/class_User.php @@ -21,17 +21,24 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class User extends BaseFrameworkSystem implements ManageableUser { +class User extends BaseFrameworkSystem implements ManageableUser, Registerable { /** - * Username + * Username of current user */ - private $username = ""; + private $userName = ""; + + /** + * Email of current user + */ + private $email = ""; // Exceptions - const EXCEPTION_USERNAME_NOT_FOUND = 0xd00; + const EXCEPTION_USERNAME_NOT_FOUND = 0x060; + const EXCEPTION_USER_EMAIL_NOT_FOUND = 0x061; + const EXCEPTION_USER_PASS_MISMATCH = 0x062; /** - * Private constructor + * Protected constructor * * @return void */ @@ -42,12 +49,6 @@ class User extends BaseFrameworkSystem implements ManageableUser { // Call parent constructor parent::__construct($class); - // Set part description - $this->setObjectDescription("Generic user class"); - - // Create unique ID number - $this->createUniqueID(); - // Clean up a little $this->removeNumberFormaters(); $this->removeSystemArray(); @@ -58,7 +59,7 @@ class User extends BaseFrameworkSystem implements ManageableUser { * factory method will check if the username is already taken and if not * so it will throw an exception. * - * @param $username Username we need a class instance for + * @param $userName Username we need a class instance for * @return $userInstance An instance of this user class * @throws UsernameMissingException If the username does not exist */ @@ -67,7 +68,7 @@ class User extends BaseFrameworkSystem implements ManageableUser { $userInstance = new User(); // Set the username - $userInstance->setUsername($userName); + $userInstance->setUserName($userName); // Check if the username exists if (!$userInstance->ifUsernameExists()) { @@ -79,14 +80,42 @@ class User extends BaseFrameworkSystem implements ManageableUser { return $userInstance; } + /** + * Creates an instance of this user class by a provided email address. This + * factory method will not check if the email address is there. + * + * @param $email Email address of the user + * @return $userInstance An instance of this user class + */ + public final static function createUserByEmail ($email) { + // Get a new instance + $userInstance = new User(); + + // Set the username + $userInstance->setEmail($email); + + // Return the instance + return $userInstance; + } + /** * Setter for username * * @param $userName The username to set * @return void */ - protected final function setUsername ($userName) { - $this->userNane = $userName; + public final function setUserName ($userName) { + $this->userName = $userName; + } + + /** + * Setter for email + * + * @param $email The email to set + * @return void + */ + protected final function setEmail ($email) { + $this->email = $email; } /** @@ -95,7 +124,16 @@ class User extends BaseFrameworkSystem implements ManageableUser { * @return $userName The username to get */ public final function getUsername () { - return $this->userNane; + return $this->userName; + } + + /** + * Getter for email + * + * @return $email The email to get + */ + public final function getEmail () { + return $this->email; } /** @@ -103,15 +141,15 @@ class User extends BaseFrameworkSystem implements ManageableUser { * * @return $exists Wether the username exists */ - protected function ifUsernameExists () { - // By default the username does exist - $exists = true; + public function ifUsernameExists () { + // By default the username does not exist + $exists = false; // Get a UserDatabaseWrapper instance - $wrapperInstance = UserDatabaseWrapper::createUserDatabaseWrapper(); + $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()); @@ -122,13 +160,93 @@ class User extends BaseFrameworkSystem implements ManageableUser { // Search for it if ($result->next()) { - // Entry found, so all is fine + // 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_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_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_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]