/** * Internal function to return a User object from a row. * @param $row array * @param $callHook boolean * @return User */ function &_returnUserFromRow(&$row, $callHook = true) { $user = new User(); $user->setId($row['user_id']); $user->setUsername($row['username']); $user->setPassword($row['password']); $user->setSalutation($row['salutation']); $user->setFirstName($row['first_name']); $user->setMiddleName($row['middle_name']); $user->setInitials($row['initials']); $user->setLastName($row['last_name']); $user->setGender($row['gender']); $user->setEmail($row['email']); $user->setUrl($row['url']); $user->setPhone($row['phone']); $user->setFax($row['fax']); $user->setMailingAddress($row['mailing_address']); $user->setCountry($row['country']); $user->setLocales(isset($row['locales']) && !empty($row['locales']) ? explode(':', $row['locales']) : array()); $user->setDateLastEmail($this->datetimeFromDB($row['date_last_email'])); $user->setDateRegistered($this->datetimeFromDB($row['date_registered'])); $user->setDateValidated($this->datetimeFromDB($row['date_validated'])); $user->setDateLastLogin($this->datetimeFromDB($row['date_last_login'])); $user->setMustChangePassword($row['must_change_password']); $user->setDisabled($row['disabled']); $user->setDisabledReason($row['disabled_reason']); $user->setAuthId($row['auth_id']); $user->setAuthStr($row['auth_str']); if ($callHook) { HookRegistry::call('UserDAO::_returnUserFromRow', array(&$user, &$row)); } return $user; }
function importUsers() { assert($this->xml->name == 'users'); import('lib.pkp.classes.user.InterestManager'); $interestManager = new InterestManager(); $roleDao =& DAORegistry::getDAO('RoleDAO'); $userDAO =& DAORegistry::getDAO('UserDAO'); $publicFileManager =& new PublicFileManager(); $site =& Request::getSite(); $siteSupportedLocales = $site->getSupportedLocales(); $this->nextElement(); while ($this->xml->name == 'user') { $userXML = $this->getCurrentElementAsDom(); $username = (string) $userXML->username; $email = (string) $userXML->email; $userByEmail = $userDAO->getUserByEmail($email); $user = null; if (!empty($userByEmail)) { $user = $userByEmail; } else { $user = new User(); $user->setUsername((string) $userXML->username); $user->setPassword((string) $userXML->password); $user->setSalutation((string) $userXML->salutation); $user->setFirstName((string) $userXML->firstName); $user->setMiddleName((string) $userXML->middleName); $user->setInitials((string) $userXML->initials); $user->setLastName((string) $userXML->lastName); $user->setSuffix((string) $userXML->suffix); $user->setGender((string) $userXML->gender); $user->setEmail((string) $userXML->email); $user->setUrl((string) $userXML->url); $user->setPhone((string) $userXML->phone); $user->setFax((string) $userXML->fax); $user->setMailingAddress((string) $userXML->mailingAddress); $user->setBillingAddress((string) $userXML->billingAddress); $user->setCountry((string) $userXML->country); $locales = array(); foreach (explode(':', (string) $userXML->locales) as $locale) { if (AppLocale::isLocaleValid($locale) && in_array($locale, $siteSupportedLocales)) { array_push($locales, $locale); } } $user->setLocales($locales); $user->setDateLastEmail((string) $userXML->dateLastEmail); $user->setDateRegistered((string) $userXML->dateRegistered); $user->setDateValidated((string) $userXML->dateValidated); $user->setDateLastLogin((string) $userXML->dateLastLogin); $user->setMustChangePassword((int) $userXML->mustChangePassword); $user->setDisabled((int) $userXML->disabled); $user->setDisabledReason((string) $userXML->disabledReason); $user->setAuthId((int) $userXML->authId); $user->setAuthStr((string) $userXML->authStr); $user->setInlineHelp((int) $userXML->inlineHelp); $this->generateUsername($user); $userDAO->insertUser($user); $this->restoreDataObjectSettings($userDAO, $userXML->settings, 'user_settings', 'user_id', $user->getId()); $user = $userDAO->getById($user->getId()); $profileImage =& $user->getSetting('profileImage'); if ($profileImage) { $oldProfileImage = $profileImage['uploadName']; $extension = $publicFileManager->getExtension($oldProfileImage); $newProfileImage = 'profileImage-' . $user->getId() . "." . $extension; $sourceFile = $this->siteFolderPath . '/' . $oldProfileImage; $publicFileManager->copyFile($sourceFile, $publicFileManager->getSiteFilesPath() . "/" . $newProfileImage); unlink($sourceFile); $profileImage['uploadName'] = $newProfileImage; $user->updateSetting('profileImage', $profileImage); } $interests = array(); foreach ($userXML->interest as $interest) { $interests[] = (string) $interest; } $interestManager->setInterestsForUser($user, $interests); } $this->idTranslationTable->register(INTERNAL_TRANSFER_OBJECT_USER, (int) $userXML->oldId, $user->getId()); foreach ($userXML->role as $roleXML) { $role = new Role(); $role->setRoleId((int) $roleXML); $role->setUserId($user->getId()); $role->setJournalId($this->journal->getId()); $roleDao->insertRole($role); } $this->nextElement(); } }
/** * Register a new user. See classes/user/form/RegistrationForm.inc.php - for how this is done for registering a user in a non-shib environment. */ function registerUserFromShib() { // Grab the names of the header fields from the config file $uin = Config::getVar('security', 'implicit_auth_header_uin'); // For TDL this is HTTP_TDL_TDLUID $first_name = Config::getVar('security', 'implicit_auth_header_first_name'); $last_name = Config::getVar('security', 'implicit_auth_header_last_name'); $email = Config::getVar('security', 'implicit_auth_header_email'); $phone = Config::getVar('security', 'implicit_auth_header_phone'); $initials = Config::getVar('security', 'implicit_auth_header_initials'); $mailing_address = Config::getVar('security', 'implicit_auth_header_mailing_address'); $uin = Config::getVar('security', 'implicit_auth_header_uin'); // Create a new user object and set it's fields from the header variables $user = new User(); $user->setAuthStr($_SERVER[$uin]); $user->setUsername($_SERVER[$email]); # Mail is userid $user->setFirstName($_SERVER[$first_name]); $user->setLastName($_SERVER[$last_name]); $user->setEmail($_SERVER[$email]); $user->setPhone($_SERVER[$phone]); $user->setMailingAddress($_SERVER[$mailing_address]); $user->setDateRegistered(Core::getCurrentDate()); // Set the user's password to their email address. This may or may not be necessary $email = Config::getVar('security', 'implicit_auth_header_email'); $user->setPassword(Validation::encryptCredentials($email, $email . 'pass')); // Now go insert the user in the db $userDao =& DAORegistry::getDAO('UserDAO'); $userDao->insertUser($user); $userId = $user->getId(); if (!$userId) { return false; } // Go put the user into the session and return it. $sessionManager =& SessionManager::getManager(); $session =& $sessionManager->getUserSession(); $session->setSessionVar('username', $user->getUsername()); return $user; }
/** * Register a new user. See classes/user/form/RegistrationForm.inc.php - for how this is done for registering a user in a non-shib environment. */ function registerUserFromShib() { // Grab the names of the header fields from the config file $uin = Config::getVar('security', 'implicit_auth_header_uin'); // For TDL this is HTTP_TDL_TDLUID $first_name = Config::getVar('security', 'implicit_auth_header_first_name'); $last_name = Config::getVar('security', 'implicit_auth_header_last_name'); $email = Config::getVar('security', 'implicit_auth_header_email'); $phone = Config::getVar('security', 'implicit_auth_header_phone'); $initials = Config::getVar('security', 'implicit_auth_header_initials'); $mailing_address = Config::getVar('security', 'implicit_auth_header_mailing_address'); $uin = Config::getVar('security', 'implicit_auth_header_uin'); // Create a new user object and set it's fields from the header variables $user = new User(); $user->setAuthStr($_SERVER[$uin]); $user->setUsername($_SERVER[$email]); # Mail is userid $user->setFirstName($_SERVER[$first_name]); $user->setLastName($_SERVER[$last_name]); $user->setEmail($_SERVER[$email]); $user->setPhone($_SERVER[$phone]); $user->setMailingAddress($_SERVER[$mailing_address]); $user->setDateRegistered(Core::getCurrentDate()); // Randomly genearate the user's password, using a randomly generated salt // Salting with a value other than the authStr/UIN prevents password-based login // (eg in the case that implicit auth is disabled later) $user->setPassword(Validation::encryptCredentials(Validation::generatePassword(40), Validation::generatePassword(40))); // Now go insert the user in the db $userDao =& DAORegistry::getDAO('UserDAO'); $userDao->insertUser($user); $userId = $user->getId(); if (!$userId) { return false; } // Go put the user into the session and return it. $sessionManager =& SessionManager::getManager(); $session =& $sessionManager->getUserSession(); $session->setSessionVar('username', $user->getUsername()); return $user; }