/**
  * Save roles settings.
  * @param $request PKPRequest
  */
 function execute($request)
 {
     $user = $request->getUser();
     // Save the roles
     import('lib.pkp.classes.user.form.UserFormHelper');
     $userFormHelper = new UserFormHelper();
     $userFormHelper->saveRoleContent($this, $user);
     // Insert the user interests
     import('lib.pkp.classes.user.InterestManager');
     $interestManager = new InterestManager();
     $interestManager->setInterestsForUser($user, $this->getData('interests'));
     parent::execute($request, $user);
 }
 /**
  * Handle a users element
  * @param $node DOMElement
  * @return array Array of User objects
  */
 function parseUser($node)
 {
     $deployment = $this->getDeployment();
     $context = $deployment->getContext();
     // Create the data object
     $userDao = DAORegistry::getDAO('UserDAO');
     $user = $userDao->newDataObject();
     // Handle metadata in subelements
     for ($n = $node->firstChild; $n !== null; $n = $n->nextSibling) {
         if (is_a($n, 'DOMElement')) {
             switch ($n->tagName) {
                 case 'username':
                     $user->setUsername($n->textContent);
                     break;
                 case 'firstname':
                     $user->setFirstName($n->textContent);
                     break;
                 case 'middlename':
                     $user->setMiddleName($n->textContent);
                     break;
                 case 'lastname':
                     $user->setLastName($n->textContent);
                     break;
                 case 'initials':
                     $user->setInitials($n->textContent);
                     break;
                 case 'salutation':
                     $user->setSalutation($n->textContent);
                     break;
                 case 'suffix':
                     $user->setSuffix($n->textContent);
                     break;
                 case 'gender':
                     $user->setGender($n->textContent);
                     break;
                 case 'affiliation':
                     $user->setAffiliation($n->textContent, $n->getAttribute('locale'));
                     break;
                 case 'country':
                     $user->setCountry($n->textContent);
                     break;
                 case 'email':
                     $user->setEmail($n->textContent);
                     break;
                 case 'url':
                     $user->setUrl($n->textContent);
                     break;
                 case 'phone':
                     $user->setPhone($n->textContent);
                     break;
                 case 'billing_address':
                     $user->setBillingAddress($n->textContent);
                     break;
                 case 'mailing_address':
                     $user->setMailingAddress($n->textContent);
                     break;
                 case 'biography':
                     $user->setBiography($n->textContent, $n->getAttribute('locale'));
                     break;
                 case 'gossip':
                     $user->setGossip($n->textContent, $n->getAttribute('locale'));
                     break;
                 case 'signature':
                     $user->setSignature($n->textContent, $n->getAttribute('locale'));
                     break;
                 case 'date_registered':
                     $user->setDateRegistered($n->textContent);
                     break;
                 case 'date_last_login':
                     $user->setDateLastLogin($n->textContent);
                     break;
                 case 'date_last_email':
                     $user->setDateLastEmail($n->textContent);
                     break;
                 case 'date_validated':
                     $user->setDateValidated($n->textContent);
                     break;
                 case 'inline_help':
                     $n->textContent == 'true' ? $user->setInlineHelp(true) : $user->setInlineHelp(false);
                     break;
                 case 'auth_id':
                     $user->setAuthId($n->textContent);
                     break;
                 case 'auth_string':
                     $user->setAuthString($n->textContent);
                     break;
                 case 'disabled_reason':
                     $user->setDisabledReason($n->textContent);
                     break;
                 case 'locales':
                     $user->setLocales(preg_split('/:/', $n->textContent));
                     break;
                 case 'password':
                     if ($n->getAttribute('must_change') == 'true') {
                         $user->setMustChangePassword(true);
                     }
                     if ($n->getAttribute('is_disabled') == 'true') {
                         $user->setIsDisabled(true);
                     }
                     $passwordValueNodeList = $n->getElementsByTagNameNS($deployment->getNamespace(), 'value');
                     if ($passwordValueNodeList->length == 1) {
                         $password = $passwordValueNodeList->item(0);
                         $user->setPassword($password->textContent);
                     } else {
                         fatalError("User has no password.  Check your import XML format.");
                     }
                     break;
             }
         }
     }
     // ensure that this username and email address are not already in use.
     if (!$userDao->getByUsername($user->getUsername(), false) && !$userDao->getUserByEmail($user->getEmail(), false)) {
         $userId = $userDao->insertObject($user);
         // Insert reviewing interests, now that there is a userId.
         $interestNodeList = $node->getElementsByTagNameNS($deployment->getNamespace(), 'review_interests');
         if ($interestNodeList->length == 0) {
             $n = $interestNodeList->item(0);
             if ($n) {
                 $interests = preg_split('/,\\s*/', $n->textContent);
                 import('lib.pkp.classes.user.InterestManager');
                 $interestManager = new InterestManager();
                 $interestManager->setInterestsForUser($user, $interests);
             }
         }
         $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
         $userGroups = $userGroupDao->getByContextId($context->getId());
         // Extract user groups from the User XML and assign the user to those (existing) groups.
         // Note:  It is possible for a user to exist with no user group assignments so there is
         // no fatalError() as is the case with PKPAuthor import.
         $userGroupNodeList = $node->getElementsByTagNameNS($deployment->getNamespace(), 'user_group_ref');
         if ($userGroupNodeList->length > 0) {
             for ($i = 0; $i < $userGroupNodeList->length; $i++) {
                 $n = $userGroupNodeList->item($i);
                 while ($userGroup = $userGroups->next()) {
                     if (in_array($n->textContent, $userGroup->getName(null))) {
                         // Found a candidate; assign user to it.
                         $userGroupDao->assignUserToGroup($userId, $userGroup->getId());
                     }
                 }
             }
         }
         return $user;
     }
 }
 /**
  * Register a new user.
  * @param $request PKPRequest
  * @return int|null User ID, or false on failure
  */
 function execute($request)
 {
     $requireValidation = Config::getVar('email', 'require_validation');
     $userDao = DAORegistry::getDAO('UserDAO');
     // New user
     $user = $userDao->newDataObject();
     $user->setUsername($this->getData('username'));
     // Set the base user fields (name, etc.)
     $user->setFirstName($this->getData('firstName'));
     $user->setMiddleName($this->getData('middleName'));
     $user->setLastName($this->getData('lastName'));
     $user->setInitials($this->getData('initials'));
     $user->setEmail($this->getData('email'));
     $user->setCountry($this->getData('country'));
     $user->setAffiliation($this->getData('affiliation'), null);
     // Localized
     $user->setDateRegistered(Core::getCurrentDate());
     $user->setInlineHelp(1);
     // default new users to having inline help visible.
     if (isset($this->defaultAuth)) {
         $user->setPassword($this->getData('password'));
         // FIXME Check result and handle failures
         $this->defaultAuth->doCreateUser($user);
         $user->setAuthId($this->defaultAuth->authId);
     }
     $user->setPassword(Validation::encryptCredentials($this->getData('username'), $this->getData('password')));
     if ($requireValidation) {
         // The account should be created in a disabled
         // state.
         $user->setDisabled(true);
         $user->setDisabledReason(__('user.login.accountNotValidated'));
     }
     parent::execute($user);
     $userDao->insertObject($user);
     $userId = $user->getId();
     if (!$userId) {
         return false;
     }
     // Associate the new user with the existing session
     $sessionManager = SessionManager::getManager();
     $session = $sessionManager->getUserSession();
     $session->setSessionVar('username', $user->getUsername());
     // Save the roles
     import('lib.pkp.classes.user.form.UserFormHelper');
     $userFormHelper = new UserFormHelper();
     $userFormHelper->saveRoleContent($this, $user);
     // Insert the user interests
     import('lib.pkp.classes.user.InterestManager');
     $interestManager = new InterestManager();
     $interestManager->setInterestsForUser($user, $this->getData('interests'));
     import('lib.pkp.classes.mail.MailTemplate');
     if ($requireValidation) {
         // Create an access key
         import('lib.pkp.classes.security.AccessKeyManager');
         $accessKeyManager = new AccessKeyManager();
         $accessKey = $accessKeyManager->createKey('RegisterContext', $user->getId(), null, Config::getVar('email', 'validation_timeout'));
         // Send email validation request to user
         $mail = new MailTemplate('USER_VALIDATE');
         $this->_setMailFrom($request, $mail);
         $context = $request->getContext();
         $mail->assignParams(array('userFullName' => $user->getFullName(), 'activateUrl' => $request->url($context->getPath(), 'user', 'activateUser', array($this->getData('username'), $accessKey))));
         $mail->addRecipient($user->getEmail(), $user->getFullName());
         $mail->send();
         unset($mail);
     }
     return $userId;
 }
예제 #4
0
 /**
  * Create or update a user.
  * @param $args array
  * @param $request PKPRequest
  */
 function &execute($args, $request)
 {
     parent::execute($request);
     $userDao = DAORegistry::getDAO('UserDAO');
     $context = $request->getContext();
     if (isset($this->userId)) {
         $userId = $this->userId;
         $user = $userDao->getById($userId);
     }
     if (!isset($user)) {
         $user = $userDao->newDataObject();
         $user->setInlineHelp(1);
         // default new users to having inline help visible
     }
     $user->setSalutation($this->getData('salutation'));
     $user->setFirstName($this->getData('firstName'));
     $user->setMiddleName($this->getData('middleName'));
     $user->setLastName($this->getData('lastName'));
     $user->setSuffix($this->getData('suffix'));
     $user->setInitials($this->getData('initials'));
     $user->setGender($this->getData('gender'));
     $user->setAffiliation($this->getData('affiliation'), null);
     // Localized
     $user->setSignature($this->getData('signature'), null);
     // Localized
     $user->setEmail($this->getData('email'));
     $user->setUrl($this->getData('userUrl'));
     $user->setPhone($this->getData('phone'));
     $user->setOrcid($this->getData('orcid'));
     $user->setMailingAddress($this->getData('mailingAddress'));
     $user->setCountry($this->getData('country'));
     $user->setBiography($this->getData('biography'), null);
     // Localized
     $user->setMustChangePassword($this->getData('mustChangePassword') ? 1 : 0);
     $user->setAuthId((int) $this->getData('authId'));
     $site = $request->getSite();
     $availableLocales = $site->getSupportedLocales();
     $locales = array();
     foreach ($this->getData('userLocales') as $locale) {
         if (AppLocale::isLocaleValid($locale) && in_array($locale, $availableLocales)) {
             array_push($locales, $locale);
         }
     }
     $user->setLocales($locales);
     if ($user->getAuthId()) {
         $authDao = DAORegistry::getDAO('AuthSourceDAO');
         $auth =& $authDao->getPlugin($user->getAuthId());
     }
     if ($user->getId() != null) {
         if ($this->getData('password') !== '') {
             if (isset($auth)) {
                 $auth->doSetUserPassword($user->getUsername(), $this->getData('password'));
                 $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword()));
                 // Used for PW reset hash only
             } else {
                 $user->setPassword(Validation::encryptCredentials($user->getUsername(), $this->getData('password')));
             }
         }
         if (isset($auth)) {
             // FIXME Should try to create user here too?
             $auth->doSetUserInfo($user);
         }
         $userDao->updateObject($user);
     } else {
         $user->setUsername($this->getData('username'));
         if ($this->getData('generatePassword')) {
             $password = Validation::generatePassword();
             $sendNotify = true;
         } else {
             $password = $this->getData('password');
             $sendNotify = $this->getData('sendNotify');
         }
         if (isset($auth)) {
             $user->setPassword($password);
             // FIXME Check result and handle failures
             $auth->doCreateUser($user);
             $user->setAuthId($auth->authId);
             $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword()));
             // Used for PW reset hash only
         } else {
             $user->setPassword(Validation::encryptCredentials($this->getData('username'), $password));
         }
         $user->setDateRegistered(Core::getCurrentDate());
         $userId = $userDao->insertObject($user);
         if ($sendNotify) {
             // Send welcome email to user
             import('lib.pkp.classes.mail.MailTemplate');
             $mail = new MailTemplate('USER_REGISTER');
             $mail->setReplyTo($context->getSetting('contactEmail'), $context->getSetting('contactName'));
             $mail->assignParams(array('username' => $this->getData('username'), 'password' => $password, 'userFullName' => $user->getFullName()));
             $mail->addRecipient($user->getEmail(), $user->getFullName());
             $mail->send();
         }
     }
     import('lib.pkp.classes.user.InterestManager');
     $interestManager = new InterestManager();
     $interestManager->setInterestsForUser($user, $this->getData('interests'));
     return $user;
 }
예제 #5
0
 /**
  * Register a new user.
  */
 function execute()
 {
     $userDao =& DAORegistry::getDAO('UserDAO');
     $journal =& Request::getJournal();
     if (isset($this->userId)) {
         $user =& $userDao->getById($this->userId);
     }
     if (!isset($user)) {
         $user = new User();
     }
     $user->setSalutation($this->getData('salutation'));
     $user->setFirstName($this->getData('firstName'));
     $user->setMiddleName($this->getData('middleName'));
     $user->setLastName($this->getData('lastName'));
     $user->setInitials($this->getData('initials'));
     $user->setGender($this->getData('gender'));
     $user->setAffiliation($this->getData('affiliation'), null);
     // Localized
     $user->setSignature($this->getData('signature'), null);
     // Localized
     $user->setEmail($this->getData('email'));
     $user->setData('orcid', $this->getData('orcid'));
     $user->setUrl($this->getData('userUrl'));
     $user->setPhone($this->getData('phone'));
     $user->setFax($this->getData('fax'));
     $user->setMailingAddress($this->getData('mailingAddress'));
     $user->setCountry($this->getData('country'));
     $user->setBiography($this->getData('biography'), null);
     // Localized
     $user->setGossip($this->getData('gossip'), null);
     // Localized
     $user->setMustChangePassword($this->getData('mustChangePassword') ? 1 : 0);
     $user->setAuthId((int) $this->getData('authId'));
     $site =& Request::getSite();
     $availableLocales = $site->getSupportedLocales();
     $locales = array();
     foreach ($this->getData('userLocales') as $locale) {
         if (AppLocale::isLocaleValid($locale) && in_array($locale, $availableLocales)) {
             array_push($locales, $locale);
         }
     }
     $user->setLocales($locales);
     if ($user->getAuthId()) {
         $authDao =& DAORegistry::getDAO('AuthSourceDAO');
         $auth =& $authDao->getPlugin($user->getAuthId());
     }
     if ($user->getId() != null) {
         $userId = $user->getId();
         if ($this->getData('password') !== '') {
             if (isset($auth)) {
                 $auth->doSetUserPassword($user->getUsername(), $this->getData('password'));
                 $user->setPassword(Validation::encryptCredentials($userId, Validation::generatePassword()));
                 // Used for PW reset hash only
             } else {
                 $user->setPassword(Validation::encryptCredentials($user->getUsername(), $this->getData('password')));
             }
         }
         if (isset($auth)) {
             // FIXME Should try to create user here too?
             $auth->doSetUserInfo($user);
         }
         $userDao->updateObject($user);
     } else {
         $user->setUsername($this->getData('username'));
         if ($this->getData('generatePassword')) {
             $password = Validation::generatePassword();
             $sendNotify = true;
         } else {
             $password = $this->getData('password');
             $sendNotify = $this->getData('sendNotify');
         }
         if (isset($auth)) {
             $user->setPassword($password);
             // FIXME Check result and handle failures
             $auth->doCreateUser($user);
             $user->setAuthId($auth->authId);
             $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword()));
             // Used for PW reset hash only
         } else {
             $user->setPassword(Validation::encryptCredentials($this->getData('username'), $password));
         }
         $user->setDateRegistered(Core::getCurrentDate());
         $userId = $userDao->insertUser($user);
         $isManager = Validation::isJournalManager();
         if (!empty($this->_data['enrollAs'])) {
             foreach ($this->getData('enrollAs') as $roleName) {
                 // Enroll new user into an initial role
                 $roleDao =& DAORegistry::getDAO('RoleDAO');
                 $roleId = $roleDao->getRoleIdFromPath($roleName);
                 if (!$isManager && $roleId != ROLE_ID_READER) {
                     continue;
                 }
                 if ($roleId != null) {
                     $role = new Role();
                     $role->setJournalId($journal->getId());
                     $role->setUserId($userId);
                     $role->setRoleId($roleId);
                     $roleDao->insertRole($role);
                 }
             }
         }
         if ($sendNotify) {
             // Send welcome email to user
             import('classes.mail.MailTemplate');
             $mail = new MailTemplate('USER_REGISTER');
             $mail->setFrom($journal->getSetting('contactEmail'), $journal->getSetting('contactName'));
             $mail->assignParams(array('username' => $this->getData('username'), 'password' => $password, 'userFullName' => $user->getFullName()));
             $mail->addRecipient($user->getEmail(), $user->getFullName());
             $mail->send();
         }
     }
     // Insert the user interests
     $interests = $this->getData('interestsKeywords') ? $this->getData('interestsKeywords') : $this->getData('interestsTextOnly');
     import('lib.pkp.classes.user.InterestManager');
     $interestManager = new InterestManager();
     $interestManager->setInterestsForUser($user, $interests);
 }
 /**
  * Save review assignment
  * @param $args array
  * @param $request PKPRequest
  */
 function execute($args, $request)
 {
     $userDao = DAORegistry::getDAO('UserDAO');
     $user = $userDao->newDataObject();
     $user->setFirstName($this->getData('firstName'));
     $user->setMiddleName($this->getData('middleName'));
     $user->setLastName($this->getData('lastName'));
     $user->setEmail($this->getData('email'));
     $authDao = DAORegistry::getDAO('AuthSourceDAO');
     $auth = $authDao->getDefaultPlugin();
     $user->setAuthId($auth ? $auth->getAuthId() : 0);
     $user->setInlineHelp(1);
     // default new reviewers to having inline help visible
     $user->setUsername($this->getData('username'));
     $password = Validation::generatePassword();
     if (isset($auth)) {
         $user->setPassword($password);
         // FIXME Check result and handle failures
         $auth->doCreateUser($user);
         $user->setAuthId($auth->authId);
         $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword()));
         // Used for PW reset hash only
     } else {
         $user->setPassword(Validation::encryptCredentials($this->getData('username'), $password));
     }
     $user->setDateRegistered(Core::getCurrentDate());
     $reviewerId = $userDao->insertObject($user);
     // Set the reviewerId in the Form for the parent class to use
     $this->setData('reviewerId', $reviewerId);
     // Insert the user interests
     import('lib.pkp.classes.user.InterestManager');
     $interestManager = new InterestManager();
     $interestManager->setInterestsForUser($user, $this->getData('interests'));
     // Assign the selected user group ID to the user
     $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
     /* @var $userGroupDao UserGroupDAO */
     $userGroupId = (int) $this->getData('userGroupId');
     $userGroupDao->assignUserToGroup($reviewerId, $userGroupId);
     if (!$this->getData('skipEmail')) {
         // Send welcome email to user
         import('lib.pkp.classes.mail.MailTemplate');
         $mail = new MailTemplate('REVIEWER_REGISTER');
         if ($mail->isEnabled()) {
             $context = $request->getContext();
             $mail->setReplyTo($context->getSetting('contactEmail'), $context->getSetting('contactName'));
             $mail->assignParams(array('username' => $this->getData('username'), 'password' => $password, 'userFullName' => $user->getFullName()));
             $mail->addRecipient($user->getEmail(), $user->getFullName());
             $mail->send($request);
         }
     }
     return parent::execute($args, $request);
 }
 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.
  */
 function execute()
 {
     $requireValidation = Config::getVar('email', 'require_validation');
     if ($this->existingUser) {
         // If using implicit auth - we hardwire that we are working on an existing user
         // Existing user in the system
         $userDao =& DAORegistry::getDAO('UserDAO');
         if ($this->implicitAuth) {
             // If we are using implicit auth - then use the session username variable - rather than data from the form
             $sessionManager =& SessionManager::getManager();
             $session =& $sessionManager->getUserSession();
             $user =& $userDao->getUserByUsername($session->getSessionVar('username'));
         } else {
             $user =& $userDao->getUserByUsername($this->getData('username'));
         }
         if ($user == null) {
             return false;
         }
         $userId = $user->getId();
     } else {
         // New user
         $user = new User();
         $user->setUsername($this->getData('username'));
         $user->setSalutation($this->getData('salutation'));
         $user->setFirstName($this->getData('firstName'));
         $user->setMiddleName($this->getData('middleName'));
         $user->setInitials($this->getData('initials'));
         $user->setLastName($this->getData('lastName'));
         $user->setGender($this->getData('gender'));
         $user->setAffiliation($this->getData('affiliation'), null);
         // Localized
         $user->setSignature($this->getData('signature'), null);
         // Localized
         $user->setEmail($this->getData('email'));
         $user->setUrl($this->getData('userUrl'));
         $user->setPhone($this->getData('phone'));
         $user->setFax($this->getData('fax'));
         $user->setMailingAddress($this->getData('mailingAddress'));
         $user->setBiography($this->getData('biography'), null);
         // Localized
         $user->setDateRegistered(Core::getCurrentDate());
         $user->setCountry($this->getData('country'));
         $site =& Request::getSite();
         $availableLocales = $site->getSupportedLocales();
         $locales = array();
         foreach ($this->getData('userLocales') as $locale) {
             if (AppLocale::isLocaleValid($locale) && in_array($locale, $availableLocales)) {
                 array_push($locales, $locale);
             }
         }
         $user->setLocales($locales);
         if (isset($this->defaultAuth)) {
             $user->setPassword($this->getData('password'));
             // FIXME Check result and handle failures
             $this->defaultAuth->doCreateUser($user);
             $user->setAuthId($this->defaultAuth->authId);
         }
         $user->setPassword(Validation::encryptCredentials($this->getData('username'), $this->getData('password')));
         if ($requireValidation) {
             // The account should be created in a disabled
             // state.
             $user->setDisabled(true);
             $user->setDisabledReason(__('user.login.accountNotValidated'));
         }
         $userDao =& DAORegistry::getDAO('UserDAO');
         $userDao->insertUser($user);
         $userId = $user->getId();
         if (!$userId) {
             return false;
         }
         // Insert the user interests
         $interests = $this->getData('interestsKeywords') ? $this->getData('interestsKeywords') : $this->getData('interestsTextOnly');
         import('lib.pkp.classes.user.InterestManager');
         $interestManager = new InterestManager();
         $interestManager->setInterestsForUser($user, $interests);
         $sessionManager =& SessionManager::getManager();
         $session =& $sessionManager->getUserSession();
         $session->setSessionVar('username', $user->getUsername());
     }
     $journal =& Request::getJournal();
     $roleDao =& DAORegistry::getDAO('RoleDAO');
     // Roles users are allowed to register themselves in
     $allowedRoles = array('reader' => 'registerAsReader', 'author' => 'registerAsAuthor', 'reviewer' => 'registerAsReviewer');
     $journalSettingsDao =& DAORegistry::getDAO('JournalSettingsDAO');
     if (!$journalSettingsDao->getSetting($journal->getId(), 'allowRegReader')) {
         unset($allowedRoles['reader']);
     }
     if (!$journalSettingsDao->getSetting($journal->getId(), 'allowRegAuthor')) {
         unset($allowedRoles['author']);
     }
     if (!$journalSettingsDao->getSetting($journal->getId(), 'allowRegReviewer')) {
         unset($allowedRoles['reviewer']);
     }
     foreach ($allowedRoles as $k => $v) {
         $roleId = $roleDao->getRoleIdFromPath($k);
         if ($this->getData($v) && !$roleDao->roleExists($journal->getId(), $userId, $roleId)) {
             $role = new Role();
             $role->setJournalId($journal->getId());
             $role->setUserId($userId);
             $role->setRoleId($roleId);
             $roleDao->insertRole($role);
         }
     }
     if (!$this->existingUser) {
         import('classes.mail.MailTemplate');
         if ($requireValidation) {
             // Create an access key
             import('lib.pkp.classes.security.AccessKeyManager');
             $accessKeyManager = new AccessKeyManager();
             $accessKey = $accessKeyManager->createKey('RegisterContext', $user->getId(), null, Config::getVar('email', 'validation_timeout'));
             // Send email validation request to user
             $mail = new MailTemplate('USER_VALIDATE');
             $mail->setFrom($journal->getSetting('contactEmail'), $journal->getSetting('contactName'));
             $mail->assignParams(array('userFullName' => $user->getFullName(), 'activateUrl' => Request::url($journal->getPath(), 'user', 'activateUser', array($this->getData('username'), $accessKey))));
             $mail->addRecipient($user->getEmail(), $user->getFullName());
             $mail->send();
             unset($mail);
         }
         if ($this->getData('sendPassword')) {
             // Send welcome email to user
             $mail = new MailTemplate('USER_REGISTER');
             $mail->setFrom($journal->getSetting('contactEmail'), $journal->getSetting('contactName'));
             $mail->assignParams(array('username' => $this->getData('username'), 'password' => String::substr($this->getData('password'), 0, 30), 'userFullName' => $user->getFullName()));
             $mail->addRecipient($user->getEmail(), $user->getFullName());
             $mail->send();
             unset($mail);
         }
     }
     if (isset($allowedRoles['reader']) && $this->getData('openAccessNotification')) {
         $userSettingsDao =& DAORegistry::getDAO('UserSettingsDAO');
         $userSettingsDao->updateSetting($userId, 'openAccessNotification', true, 'bool', $journal->getId());
     }
 }
예제 #9
0
 /**
  * Save profile settings.
  */
 function execute()
 {
     $user =& Request::getUser();
     $user->setSalutation($this->getData('salutation'));
     $user->setFirstName($this->getData('firstName'));
     $user->setMiddleName($this->getData('middleName'));
     $user->setLastName($this->getData('lastName'));
     $user->setGender($this->getData('gender'));
     $user->setInitials($this->getData('initials'));
     $user->setAffiliation($this->getData('affiliation'), null);
     // Localized
     $user->setSignature($this->getData('signature'), null);
     // Localized
     $user->setEmail($this->getData('email'));
     $user->setData('orcid', $this->getData('orcid'));
     $user->setUrl($this->getData('userUrl'));
     $user->setPhone($this->getData('phone'));
     $user->setFax($this->getData('fax'));
     $user->setMailingAddress($this->getData('mailingAddress'));
     $user->setCountry($this->getData('country'));
     $user->setBiography($this->getData('biography'), null);
     // Localized
     // Insert the user interests
     $interests = $this->getData('interestsKeywords') ? $this->getData('interestsKeywords') : $this->getData('interestsTextOnly');
     import('lib.pkp.classes.user.InterestManager');
     $interestManager = new InterestManager();
     $interestManager->setInterestsForUser($user, $interests);
     $site =& Request::getSite();
     $availableLocales = $site->getSupportedLocales();
     $locales = array();
     foreach ($this->getData('userLocales') as $locale) {
         if (AppLocale::isLocaleValid($locale) && in_array($locale, $availableLocales)) {
             array_push($locales, $locale);
         }
     }
     $user->setLocales($locales);
     parent::execute($user);
     $userDao =& DAORegistry::getDAO('UserDAO');
     $userDao->updateObject($user);
     $roleDao =& DAORegistry::getDAO('RoleDAO');
     $journalDao =& DAORegistry::getDAO('JournalDAO');
     // Roles
     $journal =& Request::getJournal();
     if ($journal) {
         $role = new Role();
         $role->setUserId($user->getId());
         $role->setJournalId($journal->getId());
         if ($journal->getSetting('allowRegReviewer')) {
             $role->setRoleId(ROLE_ID_REVIEWER);
             $hasRole = Validation::isReviewer();
             $wantsRole = Request::getUserVar('reviewerRole');
             if ($hasRole && !$wantsRole) {
                 $roleDao->deleteRole($role);
             }
             if (!$hasRole && $wantsRole) {
                 $roleDao->insertRole($role);
             }
         }
         if ($journal->getSetting('allowRegAuthor')) {
             $role->setRoleId(ROLE_ID_AUTHOR);
             $hasRole = Validation::isAuthor();
             $wantsRole = Request::getUserVar('authorRole');
             if ($hasRole && !$wantsRole) {
                 $roleDao->deleteRole($role);
             }
             if (!$hasRole && $wantsRole) {
                 $roleDao->insertRole($role);
             }
         }
         if ($journal->getSetting('allowRegReader')) {
             $role->setRoleId(ROLE_ID_READER);
             $hasRole = Validation::isReader();
             $wantsRole = Request::getUserVar('readerRole');
             if ($hasRole && !$wantsRole) {
                 $roleDao->deleteRole($role);
             }
             if (!$hasRole && $wantsRole) {
                 $roleDao->insertRole($role);
             }
         }
     }
     $openAccessNotify = Request::getUserVar('openAccessNotify');
     $userSettingsDao =& DAORegistry::getDAO('UserSettingsDAO');
     $journals =& $journalDao->getJournals(true);
     $journals =& $journals->toArray();
     foreach ($journals as $thisJournal) {
         if ($thisJournal->getSetting('publishingMode') == PUBLISHING_MODE_SUBSCRIPTION && $thisJournal->getSetting('enableOpenAccessNotification')) {
             $currentlyReceives = $user->getSetting('openAccessNotification', $thisJournal->getJournalId());
             $shouldReceive = !empty($openAccessNotify) && in_array($thisJournal->getJournalId(), $openAccessNotify);
             if ($currentlyReceives != $shouldReceive) {
                 $userSettingsDao->updateSetting($user->getId(), 'openAccessNotification', $shouldReceive, 'bool', $thisJournal->getJournalId());
             }
         }
     }
     if ($user->getAuthId()) {
         $authDao =& DAORegistry::getDAO('AuthSourceDAO');
         $auth =& $authDao->getPlugin($user->getAuthId());
     }
     if (isset($auth)) {
         $auth->doSetUserInfo($user);
     }
 }
 /**
  * Register a new user.
  * @return userId int
  */
 function execute()
 {
     $userDao =& DAORegistry::getDAO('UserDAO');
     $user = new User();
     $user->setSalutation($this->getData('salutation'));
     $user->setFirstName($this->getData('firstName'));
     $user->setMiddleName($this->getData('middleName'));
     $user->setLastName($this->getData('lastName'));
     $user->setGender($this->getData('gender'));
     $user->setInitials($this->getData('initials'));
     $user->setAffiliation($this->getData('affiliation'), null);
     // Localized
     $user->setEmail($this->getData('email'));
     $user->setData('orcid', $this->getData('orcid'));
     $user->setUrl($this->getData('userUrl'));
     $user->setPhone($this->getData('phone'));
     $user->setFax($this->getData('fax'));
     $user->setMailingAddress($this->getData('mailingAddress'));
     $user->setCountry($this->getData('country'));
     $user->setBiography($this->getData('biography'), null);
     // Localized
     $user->setGossip($this->getData('gossip'), null);
     // Localized
     $authDao =& DAORegistry::getDAO('AuthSourceDAO');
     $auth =& $authDao->getDefaultPlugin();
     $user->setAuthId($auth ? $auth->getAuthId() : 0);
     $site =& Request::getSite();
     $availableLocales = $site->getSupportedLocales();
     $locales = array();
     foreach ($this->getData('userLocales') as $locale) {
         if (AppLocale::isLocaleValid($locale) && in_array($locale, $availableLocales)) {
             array_push($locales, $locale);
         }
     }
     $user->setLocales($locales);
     $user->setUsername($this->getData('username'));
     $password = Validation::generatePassword();
     $sendNotify = $this->getData('sendNotify');
     if (isset($auth)) {
         $user->setPassword($password);
         // FIXME Check result and handle failures
         $auth->doCreateUser($user);
         $user->setAuthId($auth->authId);
         $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword()));
         // Used for PW reset hash only
     } else {
         $user->setPassword(Validation::encryptCredentials($this->getData('username'), $password));
     }
     $user->setMustChangePassword(isset($auth) ? 0 : 1);
     $user->setDateRegistered(Core::getCurrentDate());
     parent::execute($user);
     $userId = $userDao->insertUser($user);
     // Insert the user interests
     $interests = $this->getData('interestsKeywords') ? $this->getData('interestsKeywords') : $this->getData('interestsTextOnly');
     import('lib.pkp.classes.user.InterestManager');
     $interestManager = new InterestManager();
     $interestManager->setInterestsForUser($user, $interests);
     $roleDao =& DAORegistry::getDAO('RoleDAO');
     $journal =& Request::getJournal();
     $role = new Role();
     $role->setJournalId($journal->getId());
     $role->setUserId($userId);
     $role->setRoleId(ROLE_ID_REVIEWER);
     $roleDao->insertRole($role);
     if ($sendNotify) {
         // Send welcome email to user
         import('classes.mail.MailTemplate');
         $mail = new MailTemplate('REVIEWER_REGISTER');
         $mail->setReplyTo(null);
         $mail->assignParams(array('username' => $this->getData('username'), 'password' => $password, 'userFullName' => $user->getFullName()));
         $mail->addRecipient($user->getEmail(), $user->getFullName());
         $mail->send();
     }
     return $userId;
 }
예제 #11
0
 /**
  * Update user interests
  * @param $user
  */
 function _updateUserInterests($user)
 {
     // Insert the user interests
     $interests = $this->getData('interestsKeywords') ? $this->getData('interestsKeywords') : $this->getData('interestsTextOnly');
     import('lib.pkp.classes.user.InterestManager');
     $interestManager = new InterestManager();
     $interestManager->setInterestsForUser($user, $interests);
 }
    /**
     * Do the actual web SOAP service request.
     * @param $token string
     * @param $authToken string The token returned from _doAuthenticate
     * @return boolean|string True for success, an error message otherwise.
     */
    function _doUserRequest($token, $authToken)
    {
        // Build the multipart SOAP message from scratch.
        $soapMessage = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.avectra.com/2005/">
			<soapenv:Header>
				<ns:AuthorizationToken>
					<ns:Token>' . $authToken . '</ns:Token>
				</ns:AuthorizationToken>
		</soapenv:Header>
		<soapenv:Body>
			<ns:BNEGetIndividualInformation>
				<ns:SSOToken>' . $token . '</ns:SSOToken>
			</ns:BNEGetIndividualInformation>
		</soapenv:Body>
	</soapenv:Envelope>';
        // Prepare HTTP session.
        $curlCh = curl_init();
        curl_setopt($curlCh, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curlCh, CURLOPT_POST, true);
        // Set up SSL.
        curl_setopt($curlCh, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curlCh, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        // Make SOAP request.
        $ofrPlugin =& $this->_getObjectsForReviewPlugin();
        $journal =& Request::getJournal();
        curl_setopt($curlCh, CURLOPT_URL, $ofrPlugin->getSetting($journal->getId(), 'anthroNetSoapURL'));
        $extraHeaders = array('Host: avectra.aaanet.org', 'SOAPAction: "http://www.avectra.com/2005/BNEGetIndividualInformation"', 'Content-Type: text/xml;charset=UTF-8');
        curl_setopt($curlCh, CURLOPT_HTTPHEADER, $extraHeaders);
        curl_setopt($curlCh, CURLOPT_POSTFIELDS, $soapMessage);
        $result = true;
        $response = curl_exec($curlCh);
        // We do not localize our error messages as they are all
        // fatal errors anyway and must be analyzed by technical staff.
        if ($response === false) {
            $result = 'OJS-OFR: Expected string response.';
        }
        if ($result === true && ($status = curl_getinfo($curlCh, CURLINFO_HTTP_CODE)) != OFR_WS_RESPONSE_OK) {
            $result = 'OJS-OFR: Expected ' . OFR_WS_RESPONSE_OK . ' response code, got ' . $status . ' instead.';
        }
        curl_close($curlCh);
        // Check SOAP response by simple string manipulation rather
        // than instantiating a DOM.
        if (is_string($response)) {
            $request = Application::getRequest();
            /**
             * The XML returned looks something like this:
             *
             * <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
             * 		<soap:Header><AuthorizationToken xmlns="http://www.avectra.com/2005/"><Token>2a51ca85-d490-4444-802c-d247259d674a</Token></AuthorizationToken></soap:Header>
             * 		<soap:Body>
             * 			<BNEGetIndividualInformationResponse xmlns="http://www.avectra.com/2005/">
             * 				<BNEGetIndividualInformationResult>
             * 					<Individual xmlns="">
             * 						<ind_cst_key>2a51ca85-d490-9999-802c-d24XX59d674a</ind_cst_key>
             * 						<cst_recno>000001</cst_recno>
             * 						<ind_first_name>John</ind_first_name>
             * 						<ind_last_name>Public</ind_last_name>
             * 						<cst_eml_address_dn>user@email.com</cst_eml_address_dn>
             * 						<InterestCodes>&lt;InterestCode&gt;Art and Material Culture&lt;/InterestCode&gt;</InterestCodes>
             * 					</Individual>
             * 				</BNEGetIndividualInformationResult>
             * 			</BNEGetIndividualInformationResponse>
             * 		</soap:Body>
             * </soap:Envelope>
             */
            $matches = array();
            if (!preg_match('#<faultstring>([^<]*)</faultstring>#', $response)) {
                // Ensure that the user is logged into the AnthroNet portal.
                if (preg_match('#<ind_cst_key>00000000\\-0000\\-0000\\-0000\\-000000000000</ind_cst_key>#', $response)) {
                    $request->redirect(null, 'user');
                } else {
                    $email = $firstName = $lastName = $interestCodes = null;
                    $interestCodesArray = array();
                    if (preg_match('#<cst_eml_address_dn>(.*?)</cst_eml_address_dn>#', $response, $matches)) {
                        $email = $matches[1];
                    }
                    if (preg_match('#<ind_first_name>(.*?)</ind_first_name>#', $response, $matches)) {
                        $firstName = $matches[1];
                    }
                    if (preg_match('#<ind_last_name>(.*?)</ind_last_name>#', $response, $matches)) {
                        $lastName = $matches[1];
                    }
                    if (preg_match('#<InterestCodes>(.*?)</InterestCodes>#', $response, $matches)) {
                        $interestCodes = $matches[1];
                        preg_match_all('#&lt;InterestCode&gt;(.*?)&lt;/InterestCode&gt;#', $interestCodes, $matches, PREG_PATTERN_ORDER);
                        if (is_array($matches[1])) {
                            $interestCodesArray = $matches[1];
                        }
                    }
                    $userDao =& DAORegistry::getDAO('UserDAO');
                    // see if this user exists already.
                    $user = $userDao->getUserByEmail($email);
                    if (!$user) {
                        $user = new User();
                        $userName = Validation::suggestUsername($firstName, $lastName);
                        $user->setUsername($userName);
                        $user->setFirstName($firstName);
                        $user->setLastName($lastName);
                        $user->setEmail($email);
                        $user->setDateRegistered(Core::getCurrentDate());
                        $locales = array('en_US');
                        $user->setLocales($locales);
                        $user->setPassword(Validation::encryptCredentials($userName, Validation::generatePassword()));
                        $userDao->insertUser($user);
                    }
                    import('lib.pkp.classes.user.InterestManager');
                    $interestManager = new InterestManager();
                    $interestManager->setInterestsForUser($user, $interestCodesArray);
                    // enroll as Author, if not already.
                    $roleDao =& DAORegistry::getDAO('RoleDAO');
                    if (!$roleDao->userHasRole($journal->getId(), $user->getId(), ROLE_ID_AUTHOR)) {
                        $role = new Role();
                        $role->setJournalId($journal->getId());
                        $role->setUserId($user->getId());
                        $role->setRoleId(ROLE_ID_AUTHOR);
                        $roleDao->insertRole($role);
                    }
                    return $user;
                }
            } else {
                $result = 'OFR: ' . $status . ' - ' . $matches[1];
            }
        } else {
            $result = 'OJS-OFR: Expected string response.';
        }
        return false;
    }
 /**
  * Import the parsed users into the system.
  * @param $sendNotify boolean send an email notification to each imported user containing their username and password
  * @param $continueOnError boolean continue to import remaining users if a failure occurs
  * @return boolean success
  */
 function importUsers($sendNotify = false, $continueOnError = false)
 {
     $success = true;
     $this->importedUsers = array();
     $this->errors = array();
     $userDao =& DAORegistry::getDAO('UserDAO');
     $roleDao =& DAORegistry::getDAO('RoleDAO');
     if ($sendNotify) {
         // Set up mail template to send to added users
         import('classes.mail.MailTemplate');
         $mail = new MailTemplate('USER_REGISTER');
         $journalDao =& DAORegistry::getDAO('JournalDAO');
         $journal =& $journalDao->getJournal($this->journalId);
         $mail->setFrom($journal->getSetting('contactEmail'), $journal->getSetting('contactName'));
     }
     for ($i = 0, $count = count($this->usersToImport); $i < $count; $i++) {
         $user =& $this->usersToImport[$i];
         // If the email address already exists in the system,
         // then assign the user the username associated with that email address.
         if ($user->getEmail() != null) {
             $emailExists = $userDao->getUserByEmail($user->getEmail(), true);
             if ($emailExists != null) {
                 $user->setUsername($emailExists->getUsername());
             }
         }
         if ($user->getUsername() == null) {
             $newUsername = true;
             $this->generateUsername($user);
         } else {
             $newUsername = false;
         }
         if ($user->getUnencryptedPassword() != null) {
             $user->setPassword(Validation::encryptCredentials($user->getUsername(), $user->getUnencryptedPassword()));
         } else {
             if ($user->getPassword() == null) {
                 $this->generatePassword($user);
             }
         }
         if (!$newUsername) {
             // Check if user already exists
             $userExists = $userDao->getUserByUsername($user->getUsername(), true);
             if ($userExists != null) {
                 $user->setId($userExists->getId());
             }
         } else {
             $userExists = false;
         }
         if ($newUsername || !$userExists) {
             // Create new user account
             // If the user's username was specified in the data file and
             // the username already exists, only the new roles are added for that user
             if (!$userDao->insertUser($user)) {
                 // Failed to add user!
                 $this->errors[] = sprintf('%s: %s (%s)', __('manager.people.importUsers.failedToImportUser'), $user->getFullName(), $user->getUsername());
                 if ($continueOnError) {
                     // Skip to next user
                     $success = false;
                     continue;
                 } else {
                     return false;
                 }
             }
         }
         // Add reviewing interests to interests table
         $interests = $user->getTemporaryInterests();
         $interests = explode(',', $interests);
         $interests = array_map('trim', $interests);
         // Trim leading whitespace
         import('lib.pkp.classes.user.InterestManager');
         $interestManager = new InterestManager();
         $interestManager->setInterestsForUser($user, $interests);
         // Enroll user in specified roles
         // If the user is already enrolled in a role, that role is skipped
         foreach ($user->getRoles() as $role) {
             $role->setUserId($user->getId());
             $role->setJournalId($this->journalId);
             if (!$roleDao->roleExists($role->getJournalId(), $role->getUserId(), $role->getRoleId())) {
                 if (!$roleDao->insertRole($role)) {
                     // Failed to add role!
                     $this->errors[] = sprintf('%s: %s - %s (%s)', __('manager.people.importUsers.failedToImportRole'), $role->getRoleName(), $user->getFullName(), $user->getUsername());
                     if ($continueOnError) {
                         // Continue to insert other roles for this user
                         $success = false;
                         continue;
                     } else {
                         return false;
                     }
                 }
             }
         }
         if ($sendNotify && !$userExists) {
             // Send email notification to user as if user just registered themselves
             $mail->addRecipient($user->getEmail(), $user->getFullName());
             $mail->sendWithParams(array('journalName' => $journal->getTitle($journal->getPrimaryLocale()), 'username' => $user->getUsername(), 'password' => $user->getUnencryptedPassword() == null ? '-' : $user->getUnencryptedPassword(), 'userFullName' => $user->getFullName()));
             $mail->clearRecipients();
         }
         array_push($this->importedUsers, $user);
     }
     return $success;
 }
예제 #14
0
 /**
  * Register a new user.
  */
 function execute()
 {
     $requireValidation = Config::getVar('email', 'require_validation');
     if ($this->existingUser) {
         // Existing user in the system
         $userDao = DAORegistry::getDAO('UserDAO');
         $user =& $userDao->getByUsername($this->getData('username'));
         if ($user == null) {
             return false;
         }
         $userId = $user->getId();
     } else {
         // New user
         $user = new User();
         $user->setUsername($this->getData('username'));
         $user->setSalutation($this->getData('salutation'));
         $user->setFirstName($this->getData('firstName'));
         $user->setMiddleName($this->getData('middleName'));
         $user->setInitials($this->getData('initials'));
         $user->setLastName($this->getData('lastName'));
         $user->setGender($this->getData('gender'));
         $user->setAffiliation($this->getData('affiliation'), null);
         // Localized
         $user->setSignature($this->getData('signature'), null);
         // Localized
         $user->setEmail($this->getData('email'));
         $user->setUrl($this->getData('userUrl'));
         $user->setPhone($this->getData('phone'));
         $user->setFax($this->getData('fax'));
         $user->setMailingAddress($this->getData('mailingAddress'));
         $user->setBillingAddress($this->getData('billingAddress'));
         $user->setBiography($this->getData('biography'), null);
         // Localized
         $user->setDateRegistered(Core::getCurrentDate());
         $user->setCountry($this->getData('country'));
         $site =& Request::getSite();
         $availableLocales = $site->getSupportedLocales();
         $locales = array();
         foreach ($this->getData('userLocales') as $locale) {
             if (AppLocale::isLocaleValid($locale) && in_array($locale, $availableLocales)) {
                 array_push($locales, $locale);
             }
         }
         $user->setLocales($locales);
         if (isset($this->defaultAuth)) {
             $user->setPassword($this->getData('password'));
             // FIXME Check result and handle failures
             $this->defaultAuth->doCreateUser($user);
             $user->setAuthId($this->defaultAuth->authId);
         }
         $user->setPassword(Validation::encryptCredentials($this->getData('username'), $this->getData('password')));
         if ($requireValidation) {
             // The account should be created in a disabled
             // state.
             $user->setDisabled(true);
             $user->setDisabledReason(__('user.login.accountNotValidated'));
         }
         $userDao = DAORegistry::getDAO('UserDAO');
         $userDao->insertObject($user);
         $userId = $user->getId();
         if (!$userId) {
             return false;
         }
         // Insert the user interests
         $interests = $this->getData('interestsKeywords') ? $this->getData('interestsKeywords') : $this->getData('interestsTextOnly');
         import('lib.pkp.classes.user.InterestManager');
         $interestManager = new InterestManager();
         $interestManager->setInterestsForUser($user, $interests);
         $sessionManager =& SessionManager::getManager();
         $session =& $sessionManager->getUserSession();
         $session->setSessionVar('username', $user->getUsername());
     }
     $conference =& Request::getConference();
     $schedConf =& Request::getSchedConf();
     $roleDao = DAORegistry::getDAO('RoleDAO');
     // Roles users are allowed to register themselves in
     $allowedRoles = array('reader' => 'createAsReader', 'author' => 'createAsAuthor', 'reviewer' => 'createAsReviewer');
     import('classes.schedConf.SchedConfAction');
     if (!SchedConfAction::allowRegReader($schedConf)) {
         unset($allowedRoles['reader']);
     }
     if (!SchedConfAction::allowRegAuthor($schedConf)) {
         unset($allowedRoles['author']);
     }
     if (!SchedConfAction::allowRegReviewer($schedConf)) {
         unset($allowedRoles['reviewer']);
     }
     foreach ($allowedRoles as $k => $v) {
         $roleId = $roleDao->getRoleIdFromPath($k);
         if ($this->getData($v) && !$roleDao->userHasRole($conference->getId(), $schedConf->getId(), $userId, $roleId)) {
             $role = new Role();
             $role->setConferenceId($conference->getId());
             $role->setSchedConfId($schedConf->getId());
             $role->setUserId($userId);
             $role->setRoleId($roleId);
             $roleDao->insertRole($role);
         }
     }
     if (!$this->existingUser) {
         $this->sendConfirmationEmail($user, $this->getData('password'), $this->getData('sendPassword'));
     }
     if (isset($allowedRoles['reader']) && $this->getData('openAccessNotification')) {
         $userSettingsDao = DAORegistry::getDAO('UserSettingsDAO');
         $userSettingsDao->updateSetting($userId, 'openAccessNotification', true, 'bool', $conference->getId());
     }
 }