/**
  * Save new password.
  * @return boolean success
  */
 function execute()
 {
     $userDao =& DAORegistry::getDAO('UserDAO');
     $user =& $userDao->getUserByUsername($this->getData('username'), false);
     echo $user->getUsername();
     echo $this->getData('password');
     if ($user != null) {
         if ($user->getAuthId()) {
             $authDao =& DAORegistry::getDAO('AuthSourceDAO');
             $auth =& $authDao->getPlugin($user->getAuthId());
         }
         if (isset($auth)) {
             $auth->doSetUserPassword($user->getUsername(), $this->getData('password'));
             $user->setPassword(Validation::encryptCredentials($user->getUserId(), Validation::generatePassword()));
             // Used for PW reset hash only
         } else {
             echo $user->getUsername();
             echo $this->getData('password');
             $user->setPassword(Validation::encryptCredentials($user->getUsername(), $this->getData('password')));
         }
         $user->setMustChangePassword(0);
         $userDao->updateUser($user);
         return true;
     } else {
         return false;
     }
 }
 /**
  * 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->setMustChangePassword(true);
     // Emailed P/W not safe
     $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);
 }
Beispiel #3
0
 /**
  * Create initial required data.
  * @return boolean
  */
 function createData()
 {
     if ($this->getParam('manualInstall')) {
         // Add insert statements for default data
         // FIXME use ADODB data dictionary?
         $this->executeSQL(sprintf('INSERT INTO site (primary_locale, installed_locales) VALUES (\'%s\', \'%s\')', $this->getParam('locale'), join(':', $this->installedLocales)));
         $this->executeSQL(sprintf('INSERT INTO site_settings (setting_name, setting_type, setting_value, locale) VALUES (\'%s\', \'%s\', \'%s\', \'%s\')', 'title', 'string', addslashes(Locale::translate(INSTALLER_DEFAULT_SITE_TITLE)), $this->getParam('locale')));
         $this->executeSQL(sprintf('INSERT INTO site_settings (setting_name, setting_type, setting_value, locale) VALUES (\'%s\', \'%s\', \'%s\', \'%s\')', 'contactName', 'string', addslashes(Locale::translate(INSTALLER_DEFAULT_SITE_TITLE)), $this->getParam('locale')));
         $this->executeSQL(sprintf('INSERT INTO site_settings (setting_name, setting_type, setting_value, locale) VALUES (\'%s\', \'%s\', \'%s\', \'%s\')', 'contactEmail', 'string', addslashes($this->getParam('adminEmail')), $this->getParam('locale')));
         $this->executeSQL(sprintf('INSERT INTO users (user_id, username, first_name, last_name, password, email, date_registered, date_last_login) VALUES (%d, \'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\')', 1, $this->getParam('adminUsername'), $this->getParam('adminUsername'), $this->getParam('adminUsername'), Validation::encryptCredentials($this->getParam('adminUsername'), $this->getParam('adminPassword'), $this->getParam('encryption')), $this->getParam('adminEmail'), Core::getCurrentDate(), Core::getCurrentDate()));
         $this->executeSQL(sprintf('INSERT INTO roles (journal_id, user_id, role_id) VALUES (%d, %d, %d)', 0, 1, ROLE_ID_SITE_ADMIN));
     } else {
         // Add initial site data
         $locale = $this->getParam('locale');
         $siteDao =& DAORegistry::getDAO('SiteDAO', $this->dbconn);
         $site =& new Site();
         $site->setRedirect(0);
         $site->setMinPasswordLength(INSTALLER_DEFAULT_MIN_PASSWORD_LENGTH);
         $site->setPrimaryLocale($locale);
         $site->setInstalledLocales($this->installedLocales);
         $site->setSupportedLocales($this->installedLocales);
         if (!$siteDao->insertSite($site)) {
             $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
             return false;
         }
         $siteSettingsDao =& DAORegistry::getDAO('SiteSettingsDAO');
         $siteSettingsDao->updateSetting('title', array($locale => Locale::translate(INSTALLER_DEFAULT_SITE_TITLE)), null, true);
         $siteSettingsDao->updateSetting('contactName', array($locale => Locale::translate(INSTALLER_DEFAULT_SITE_TITLE)), null, true);
         $siteSettingsDao->updateSetting('contactEmail', array($locale => $this->getParam('adminEmail')), null, true);
         // Add initial site administrator user
         $userDao =& DAORegistry::getDAO('UserDAO', $this->dbconn);
         $user =& new User();
         $user->setUsername($this->getParam('adminUsername'));
         $user->setPassword(Validation::encryptCredentials($this->getParam('adminUsername'), $this->getParam('adminPassword'), $this->getParam('encryption')));
         $user->setFirstName($user->getUsername());
         $user->setLastName('');
         $user->setEmail($this->getParam('adminEmail'));
         if (!$userDao->insertUser($user)) {
             $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
             return false;
         }
         $roleDao =& DAORegistry::getDao('RoleDAO', $this->dbconn);
         $role =& new Role();
         $role->setJournalId(0);
         $role->setUserId($user->getUserId());
         $role->setRoleId(ROLE_ID_SITE_ADMIN);
         if (!$roleDao->insertRole($role)) {
             $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
             return false;
         }
     }
     return true;
 }
 /**
  * Verify if the input password is correct
  *
  * @param string $username the string username
  * @param string $password the plaintext password
  * @param string $hash the password hash from the database
  * @param string &$rehash if password needs rehash, this variable is used
  * @return boolean
  */
 function verifyPassword($username, $password, $hash, &$rehash)
 {
     if (password_needs_rehash($hash, PASSWORD_BCRYPT)) {
         // update to new hashing algorithm
         $oldHash = Validation::encryptCredentials($username, $password, false, true);
         if ($oldHash === $hash) {
             // update hash
             $rehash = Validation::encryptCredentials($username, $password);
             return true;
         }
     }
     return password_verify($password, $hash);
 }
 /**
  * Create initial required data.
  * @return boolean
  */
 function createData()
 {
     // Add initial site data
     $locale = $this->getParam('locale');
     $siteDao =& DAORegistry::getDAO('SiteDAO', $this->dbconn);
     $site = new Site();
     $site->setRedirect(0);
     $site->setMinPasswordLength(INSTALLER_DEFAULT_MIN_PASSWORD_LENGTH);
     $site->setPrimaryLocale($locale);
     $site->setInstalledLocales($this->installedLocales);
     $site->setSupportedLocales($this->installedLocales);
     if (!$siteDao->insertSite($site)) {
         $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
         return false;
     }
     $siteSettingsDao =& DAORegistry::getDAO('SiteSettingsDAO');
     $siteSettingsDao->updateSetting('title', array($locale => __(INSTALLER_DEFAULT_SITE_TITLE)), null, true);
     $siteSettingsDao->updateSetting('contactName', array($locale => __(INSTALLER_DEFAULT_SITE_TITLE)), null, true);
     $siteSettingsDao->updateSetting('contactEmail', array($locale => $this->getParam('adminEmail')), null, true);
     // Add initial site administrator user
     $userDao =& DAORegistry::getDAO('UserDAO', $this->dbconn);
     $user = new User();
     $user->setUsername($this->getParam('adminUsername'));
     $user->setPassword(Validation::encryptCredentials($this->getParam('adminUsername'), $this->getParam('adminPassword'), $this->getParam('encryption')));
     $user->setFirstName($user->getUsername());
     $user->setLastName('');
     $user->setEmail($this->getParam('adminEmail'));
     if (!$userDao->insertUser($user)) {
         $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
         return false;
     }
     $roleDao =& DAORegistry::getDao('RoleDAO', $this->dbconn);
     $role = new Role();
     $role->setJournalId(0);
     $role->setUserId($user->getId());
     $role->setRoleId(ROLE_ID_SITE_ADMIN);
     if (!$roleDao->insertRole($role)) {
         $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
         return false;
     }
     // Install email template list and data for each locale
     $emailTemplateDao =& DAORegistry::getDAO('EmailTemplateDAO');
     $emailTemplateDao->installEmailTemplates($emailTemplateDao->getMainEmailTemplatesFilename());
     foreach ($this->installedLocales as $locale) {
         $emailTemplateDao->installEmailTemplateData($emailTemplateDao->getMainEmailTemplateDataFilename($locale));
     }
     // Install filters and filter templates.
     $this->installFilterTemplates();
     return true;
 }
 /**
  * Save new password.
  */
 function execute()
 {
     $user = $this->getUser();
     if ($user->getAuthId()) {
         $authDao = DAORegistry::getDAO('AuthSourceDAO');
         $auth = $authDao->getPlugin($user->getAuthId());
     }
     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')));
     }
     $userDao = DAORegistry::getDAO('UserDAO');
     $userDao->updateObject($user);
 }
 /**
  * Reset a user's password
  * @param $args array first param contains the username of the user whose password is to be reset
  */
 function resetPassword($args)
 {
     $this->validate();
     $this->setupTemplate();
     $username = isset($args[0]) ? $args[0] : null;
     $userDao =& DAORegistry::getDAO('UserDAO');
     $confirmHash = Request::getUserVar('confirm');
     if ($username == null || ($user =& $userDao->getUserByUsername($username)) == null) {
         PKPRequest::redirect(null, null, 'lostPassword');
         return;
     }
     $templateMgr =& TemplateManager::getManager();
     $hash = Validation::generatePasswordResetHash($user->getId());
     if ($hash == false || $confirmHash != $hash) {
         $templateMgr->assign('errorMsg', 'user.login.lostPassword.invalidHash');
         $templateMgr->assign('backLink', PKPRequest::url(null, null, 'lostPassword'));
         $templateMgr->assign('backLinkLabel', 'user.login.resetPassword');
         $templateMgr->display('common/error.tpl');
     } else {
         // Reset password
         $newPassword = Validation::generatePassword();
         if ($user->getAuthId()) {
             $authDao =& DAORegistry::getDAO('AuthSourceDAO');
             $auth =& $authDao->getPlugin($user->getAuthId());
         }
         if (isset($auth)) {
             $auth->doSetUserPassword($user->getUsername(), $newPassword);
             $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword()));
             // Used for PW reset hash only
         } else {
             $user->setPassword(Validation::encryptCredentials($user->getUsername(), $newPassword));
         }
         $user->setMustChangePassword(1);
         $userDao->updateObject($user);
         // Send email with new password
         $site =& Request::getSite();
         import('classes.mail.MailTemplate');
         $mail = new MailTemplate('PASSWORD_RESET');
         $this->_setMailFrom($mail);
         $mail->assignParams(array('username' => $user->getUsername(), 'password' => $newPassword, 'siteTitle' => $site->getLocalizedTitle()));
         $mail->addRecipient($user->getEmail(), $user->getFullName());
         $mail->send();
         $templateMgr->assign('pageTitle', 'user.login.resetPassword');
         $templateMgr->assign('message', 'user.login.lostPassword.passwordSent');
         $templateMgr->assign('backLink', PKPRequest::url(null, Request::getRequestedPage()));
         $templateMgr->assign('backLinkLabel', 'user.login');
         $templateMgr->display('common/message.tpl');
     }
 }
 /**
  * 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 (Locale::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(Locale::translate('user.login.accountNotValidated'));
         }
         $userDao =& DAORegistry::getDAO('UserDAO');
         $userDao->insertUser($user);
         $userId = $user->getId();
         if (!$userId) {
             return false;
         }
         // Add reviewing interests to interests table
         import('lib.pkp.classes.user.InterestManager');
         $interestManager = new InterestManager();
         $interestManager->insertInterests($userId, $this->getData('interestsKeywords'), $this->getData('interests'));
         $sessionManager =& SessionManager::getManager();
         $session =& $sessionManager->getUserSession();
         $session->setSessionVar('username', $user->getUsername());
     }
     $press =& Request::getPress();
     $roleDao =& DAORegistry::getDAO('RoleDAO');
     // Roles users are allowed to register themselves in
     $allowedRoles = array('reader' => 'registerAsReader', 'author' => 'registerAsAuthor', 'reviewer' => 'registerAsReviewer');
     $pressSettingsDao =& DAORegistry::getDAO('PressSettingsDAO');
     if (!$pressSettingsDao->getSetting($press->getId(), 'allowRegReader')) {
         unset($allowedRoles['reader']);
     }
     if (!$pressSettingsDao->getSetting($press->getId(), 'allowRegAuthor')) {
         unset($allowedRoles['author']);
     }
     if (!$pressSettingsDao->getSetting($press->getId(), 'allowRegReviewer')) {
         unset($allowedRoles['reviewer']);
     }
     foreach ($allowedRoles as $k => $v) {
         $roleId = $roleDao->getRoleIdFromPath($k);
         if ($this->getData($v) && !$roleDao->userHasRole($press->getId(), $userId, $roleId)) {
             $role = new Role();
             $role->setPressId($press->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($press->getSetting('contactEmail'), $press->getSetting('contactName'));
             $mail->assignParams(array('userFullName' => $user->getFullName(), 'activateUrl' => Request::url($press->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($press->getSetting('contactEmail'), $press->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);
         }
     }
     // By default, self-registering readers will receive
     // press updates. (The double set is here to prevent a
     // duplicate insert error msg if there was a notification entry
     // left over from a previous role.)
     if (isset($allowedRoles['reader']) && $this->getData($allowedRoles['reader'])) {
         $notificationStatusDao =& DAORegistry::getDAO('NotificationStatusDAO');
         $notificationStatusDao->setPressNotifications($press->getId(), $userId, false);
         $notificationStatusDao->setPressNotifications($press->getId(), $userId, true);
     }
 }
 /**
  * Register a new user.
  */
 function execute()
 {
     $userDao =& DAORegistry::getDAO('UserDAO');
     $journal =& Request::getJournal();
     if (isset($this->userId)) {
         $user =& $userDao->getUser($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'));
     $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->setCountry($this->getData('country'));
     $user->setBiography($this->getData('biography'), null);
     // Localized
     $user->setInterests($this->getData('interests'), 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 (Locale::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->getUserId() != null) {
         if ($this->getData('password') !== '') {
             if (isset($auth)) {
                 $auth->doSetUserPassword($user->getUsername(), $this->getData('password'));
                 $user->setPassword(Validation::encryptCredentials($user->getUserId(), 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->updateUser($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->getUserId(), 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->getJournalId());
                     $role->setUserId($userId);
                     $role->setRoleId($roleId);
                     $roleDao->insertRole($role);
                 }
             }
         }
         if ($sendNotify) {
             // Send welcome email to user
             import('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();
         }
     }
 }
 /**
  * Generate a random password for a user.
  * @param $user ImportedUser the user to be modified by this function
  */
 function generatePassword(&$user)
 {
     $password = Validation::generatePassword();
     $user->setUnencryptedPassword($password);
     $user->setPassword(Validation::encryptCredentials($user->getUsername(), $password));
 }
Beispiel #11
0
 /**
  * Create initial required data.
  * @return boolean
  */
 function createData()
 {
     if ($this->getParam('manualInstall')) {
         // Add insert statements for default data
         // FIXME use ADODB data dictionary?
         $this->executeSQL(sprintf('INSERT INTO site (primary_locale, installed_locales) VALUES (\'%s\', \'%s\')', $this->getParam('locale'), join(':', $this->installedLocales)));
         $this->executeSQL(sprintf('INSERT INTO site_settings (setting_name, setting_type, setting_value, locale) VALUES (\'%s\', \'%s\', \'%s\', \'%s\')', 'title', 'string', addslashes(Locale::translate(INSTALLER_DEFAULT_SITE_TITLE)), $this->getParam('locale')));
         $this->executeSQL(sprintf('INSERT INTO site_settings (setting_name, setting_type, setting_value, locale) VALUES (\'%s\', \'%s\', \'%s\', \'%s\')', 'contactName', 'string', addslashes(Locale::translate(INSTALLER_DEFAULT_SITE_TITLE)), $this->getParam('locale')));
         $this->executeSQL(sprintf('INSERT INTO site_settings (setting_name, setting_type, setting_value, locale) VALUES (\'%s\', \'%s\', \'%s\', \'%s\')', 'contactEmail', 'string', addslashes($this->getParam('adminEmail')), $this->getParam('locale')));
         $this->executeSQL(sprintf('INSERT INTO users (user_id, username, first_name, last_name, password, email, date_registered, date_last_login) VALUES (%d, \'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\')', 1, $this->getParam('adminUsername'), $this->getParam('adminUsername'), $this->getParam('adminUsername'), Validation::encryptCredentials($this->getParam('adminUsername'), $this->getParam('adminPassword'), $this->getParam('encryption')), $this->getParam('adminEmail'), Core::getCurrentDate(), Core::getCurrentDate()));
         $this->executeSQL(sprintf('INSERT INTO roles (press_id, user_id, role_id) VALUES (%d, %d, %d)', 0, 1, ROLE_ID_SITE_ADMIN));
         // Install email template list and data for each locale
         $emailTemplateDao =& DAORegistry::getDAO('EmailTemplateDAO');
         foreach ($emailTemplateDao->installEmailTemplates($emailTemplateDao->getMainEmailTemplatesFilename(), true) as $sql) {
             $this->executeSQL($sql);
         }
         foreach ($this->installedLocales as $locale) {
             foreach ($emailTemplateDao->installEmailTemplateData($emailTemplateDao->getMainEmailTemplateDataFilename($locale), true) as $sql) {
                 $this->executeSQL($sql);
             }
         }
     } else {
         // Add initial site data
         $locale = $this->getParam('locale');
         $siteDao =& DAORegistry::getDAO('SiteDAO', $this->dbconn);
         $site = new Site();
         $site->setRedirect(0);
         $site->setMinPasswordLength(INSTALLER_DEFAULT_MIN_PASSWORD_LENGTH);
         $site->setPrimaryLocale($locale);
         $site->setInstalledLocales($this->installedLocales);
         $site->setSupportedLocales($this->installedLocales);
         if (!$siteDao->insertSite($site)) {
             $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
             return false;
         }
         // Install email template list and data for each locale
         $emailTemplateDao =& DAORegistry::getDAO('EmailTemplateDAO');
         $emailTemplateDao->installEmailTemplates($emailTemplateDao->getMainEmailTemplatesFilename());
         foreach ($this->installedLocales as $locale) {
             $emailTemplateDao->installEmailTemplateData($emailTemplateDao->getMainEmailTemplateDataFilename($locale));
         }
         $siteSettingsDao =& DAORegistry::getDAO('SiteSettingsDAO');
         $siteSettingsDao->updateSetting('title', array($locale => Locale::translate(INSTALLER_DEFAULT_SITE_TITLE)), null, true);
         $siteSettingsDao->updateSetting('contactName', array($locale => Locale::translate(INSTALLER_DEFAULT_SITE_TITLE)), null, true);
         $siteSettingsDao->updateSetting('contactEmail', array($locale => $this->getParam('adminEmail')), null, true);
         // Add initial site administrator user
         $userDao =& DAORegistry::getDAO('UserDAO', $this->dbconn);
         $user = new User();
         $user->setUsername($this->getParam('adminUsername'));
         $user->setPassword(Validation::encryptCredentials($this->getParam('adminUsername'), $this->getParam('adminPassword'), $this->getParam('encryption')));
         $user->setFirstName($user->getUsername());
         $user->setLastName('');
         $user->setEmail($this->getParam('adminEmail'));
         if (!$userDao->insertUser($user)) {
             $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
             return false;
         }
         // Create an admin user group
         Locale::requireComponents(array(LOCALE_COMPONENT_OMP_DEFAULT_SETTINGS));
         $userGroupDao =& DAORegistry::getDao('UserGroupDAO', $this->dbconn);
         $adminUserGroup = new UserGroup();
         $adminUserGroup->setRoleId(ROLE_ID_SITE_ADMIN);
         $adminUserGroup->setContextId(0);
         $adminUserGroup->setPath(ROLE_PATH_SITE_ADMIN);
         $adminUserGroup->setDefault(true);
         foreach ($this->installedLocales as $locale) {
             $name = Locale::translate('default.groups.name.siteAdmin', array(), $locale);
             $namePlural = Locale::translate('default.groups.plural.siteAdmin', array(), $locale);
             $adminUserGroup->setData('name', $name, $locale);
             $adminUserGroup->setData('namePlural', $namePlural, $locale);
         }
         if (!$userGroupDao->insertUserGroup($adminUserGroup)) {
             $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
             return false;
         }
         // put the installer into this user group
         if (!$userGroupDao->assignUserToGroup($user->getId(), $adminUserGroup->getId())) {
             $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
             return false;
         }
     }
     return true;
 }
Beispiel #12
0
 /**
  * Create initial required data.
  * @return boolean
  */
 function createData()
 {
     // Add initial site administrator user
     $userDao = DAORegistry::getDAO('UserDAO', $this->dbconn);
     $user = $userDao->newDataObject();
     $user->setUsername($this->getParam('adminUsername'));
     $user->setPassword(Validation::encryptCredentials($this->getParam('adminUsername'), $this->getParam('adminPassword'), $this->getParam('encryption')));
     $user->setFirstName($user->getUsername());
     $user->setLastName('');
     $user->setEmail($this->getParam('adminEmail'));
     $user->setInlineHelp(1);
     if (!$userDao->insertObject($user)) {
         $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
         return false;
     }
     // Create an admin user group
     AppLocale::requireComponents(LOCALE_COMPONENT_PKP_DEFAULT);
     $userGroupDao = DAORegistry::getDao('UserGroupDAO', $this->dbconn);
     $adminUserGroup = $userGroupDao->newDataObject();
     $adminUserGroup->setRoleId(ROLE_ID_SITE_ADMIN);
     $adminUserGroup->setContextId(CONTEXT_ID_NONE);
     $adminUserGroup->setDefault(true);
     foreach ($this->installedLocales as $locale) {
         $name = __('default.groups.name.siteAdmin', array(), $locale);
         $namePlural = __('default.groups.plural.siteAdmin', array(), $locale);
         $adminUserGroup->setData('name', $name, $locale);
         $adminUserGroup->setData('namePlural', $namePlural, $locale);
     }
     if (!$userGroupDao->insertObject($adminUserGroup)) {
         $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
         return false;
     }
     // Put the installer into this user group
     $userGroupDao->assignUserToGroup($user->getId(), $adminUserGroup->getId());
     // Add initial site data
     $locale = $this->getParam('locale');
     $siteDao = DAORegistry::getDAO('SiteDAO', $this->dbconn);
     $site = $siteDao->newDataObject();
     $site->setRedirect(0);
     $site->setMinPasswordLength(INSTALLER_DEFAULT_MIN_PASSWORD_LENGTH);
     $site->setPrimaryLocale($locale);
     $site->setInstalledLocales($this->installedLocales);
     $site->setSupportedLocales($this->installedLocales);
     if (!$siteDao->insertSite($site)) {
         $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
         return false;
     }
     // Install email template list and data for each locale
     $emailTemplateDao = DAORegistry::getDAO('EmailTemplateDAO');
     $emailTemplateDao->installEmailTemplates($emailTemplateDao->getMainEmailTemplatesFilename());
     foreach ($this->installedLocales as $locale) {
         $emailTemplateDao->installEmailTemplateData($emailTemplateDao->getMainEmailTemplateDataFilename($locale));
     }
     // Install default site settings
     $siteSettingsDao = DAORegistry::getDAO('SiteSettingsDAO');
     $siteSettingsDao->installSettings('registry/siteSettings.xml', array('contactEmail' => $this->getParam('adminEmail')));
     return true;
 }
 /**
  * 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;
 }
Beispiel #14
0
 /**
  * Create initial required data.
  * @return boolean
  */
 function createData()
 {
     if ($this->getParam('manualInstall')) {
         // Add insert statements for default data
         // FIXME use ADODB data dictionary?
         $this->executeSQL(sprintf('INSERT INTO site (primary_locale, installed_locales) VALUES (\'%s\', \'%s\')', $this->getParam('locale'), join(':', $this->installedLocales)));
         $this->executeSQL(sprintf('INSERT INTO site_settings (setting_name, setting_type, setting_value, locale) VALUES (\'%s\', \'%s\', \'%s\', \'%s\')', 'title', 'string', addslashes(Locale::translate(INSTALLER_DEFAULT_SITE_TITLE)), $this->getParam('locale')));
         $this->executeSQL(sprintf('INSERT INTO site_settings (setting_name, setting_type, setting_value, locale) VALUES (\'%s\', \'%s\', \'%s\', \'%s\')', 'contactName', 'string', addslashes(Locale::translate(INSTALLER_DEFAULT_SITE_TITLE)), $this->getParam('locale')));
         $this->executeSQL(sprintf('INSERT INTO site_settings (setting_name, setting_type, setting_value, locale) VALUES (\'%s\', \'%s\', \'%s\', \'%s\')', 'contactEmail', 'string', addslashes($this->getParam('adminEmail')), $this->getParam('locale')));
         $this->executeSQL(sprintf('INSERT INTO users (username, first_name, last_name, password, email, date_registered, date_last_login) VALUES (\'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\')', $this->getParam('adminUsername'), $this->getParam('adminUsername'), $this->getParam('adminUsername'), Validation::encryptCredentials($this->getParam('adminUsername'), $this->getParam('adminPassword'), $this->getParam('encryption')), $this->getParam('adminEmail'), Core::getCurrentDate(), Core::getCurrentDate()));
         $this->executeSQL(sprintf('INSERT INTO roles (conference_id, user_id, role_id) VALUES (%d, (SELECT user_id FROM users WHERE username = \'%s\'), %d)', 0, $this->getParam('adminUsername'), ROLE_ID_SITE_ADMIN));
         // Install email template list and data for each locale
         $emailTemplateDao =& DAORegistry::getDAO('EmailTemplateDAO');
         foreach ($emailTemplateDao->installEmailTemplates($emailTemplateDao->getMainEmailTemplatesFilename(), true) as $sql) {
             $this->executeSQL($sql);
         }
         foreach ($this->installedLocales as $locale) {
             foreach ($emailTemplateDao->installEmailTemplateData($emailTemplateDao->getMainEmailTemplateDataFilename($locale), true) as $sql) {
                 $this->executeSQL($sql);
             }
         }
     } else {
         // Add initial site data
         $locale = $this->getParam('locale');
         $siteDao =& DAORegistry::getDAO('SiteDAO', $this->dbconn);
         $site = new Site();
         $site->setRedirect(0);
         $site->setMinPasswordLength(INSTALLER_DEFAULT_MIN_PASSWORD_LENGTH);
         $site->setPrimaryLocale($locale);
         $site->setInstalledLocales($this->installedLocales);
         $site->setSupportedLocales($this->installedLocales);
         if (!$siteDao->insertSite($site)) {
             $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
             return false;
         }
         $siteSettingsDao =& DAORegistry::getDAO('SiteSettingsDAO');
         $siteSettingsDao->updateSetting('title', array($locale => Locale::translate(INSTALLER_DEFAULT_SITE_TITLE)), null, true);
         $siteSettingsDao->updateSetting('contactName', array($locale => Locale::translate(INSTALLER_DEFAULT_SITE_TITLE)), null, true);
         $siteSettingsDao->updateSetting('contactEmail', array($locale => $this->getParam('adminEmail')), null, true);
         // Add initial site administrator user
         $userDao =& DAORegistry::getDAO('UserDAO', $this->dbconn);
         $user = new User();
         $user->setUsername($this->getParam('adminUsername'));
         $user->setPassword(Validation::encryptCredentials($this->getParam('adminUsername'), $this->getParam('adminPassword'), $this->getParam('encryption')));
         $user->setFirstName($user->getUsername());
         $user->setLastName('');
         $user->setEmail($this->getParam('adminEmail'));
         if (!$userDao->insertUser($user)) {
             $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
             return false;
         }
         $roleDao =& DAORegistry::getDao('RoleDAO', $this->dbconn);
         $role = new Role();
         $role->setConferenceId(0);
         $role->setUserId($user->getId());
         $role->setRoleId(ROLE_ID_SITE_ADMIN);
         if (!$roleDao->insertRole($role)) {
             $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
             return false;
         }
         // Install email template list and data for each locale
         $emailTemplateDao =& DAORegistry::getDAO('EmailTemplateDAO');
         $emailTemplateDao->installEmailTemplates($emailTemplateDao->getMainEmailTemplatesFilename());
         foreach ($this->installedLocales as $locale) {
             $emailTemplateDao->installEmailTemplateData($emailTemplateDao->getMainEmailTemplateDataFilename($locale));
         }
         // Add initial plugin data to versions table
         $versionDao =& DAORegistry::getDAO('VersionDAO');
         import('site.VersionCheck');
         $categories = PluginRegistry::getCategories();
         foreach ($categories as $category) {
             PluginRegistry::loadCategory($category, true);
             $plugins = PluginRegistry::getPlugins($category);
             foreach ($plugins as $plugin) {
                 $versionFile = $plugin->getPluginPath() . '/version.xml';
                 if (FileManager::fileExists($versionFile)) {
                     $versionInfo =& VersionCheck::parseVersionXML($versionFile);
                     $pluginVersion = $versionInfo['version'];
                     $pluginVersion->setCurrent(1);
                     $versionDao->insertVersion($pluginVersion);
                 } else {
                     $pluginVersion = new Version();
                     $pluginVersion->setMajor(1);
                     $pluginVersion->setMinor(0);
                     $pluginVersion->setRevision(0);
                     $pluginVersion->setBuild(0);
                     $pluginVersion->setDateInstalled(Core::getCurrentDate());
                     $pluginVersion->setCurrent(1);
                     $pluginVersion->setProductType('plugins.' . $category);
                     $pluginVersion->setProduct(basename($plugin->getPluginPath()));
                     $versionDao->insertVersion($pluginVersion);
                 }
             }
         }
     }
     return true;
 }
Beispiel #15
0
 /**
  * Save review assignment
  * @param $args array
  * @param $request PKPRequest
  */
 function execute($args, &$request)
 {
     $seriesEditorSubmissionDao =& DAORegistry::getDAO('SeriesEditorSubmissionDAO');
     $submission =& $seriesEditorSubmissionDao->getSeriesEditorSubmission($this->getMonographId());
     $press =& $request->getPress();
     $reviewType = $this->getData('reviewType');
     $round = $this->getData('round');
     $reviewDueDate = $this->getData('reviewDueDate');
     $responseDueDate = $this->getData('responseDueDate');
     $selectionType = (int) $this->getData('selectionType');
     if ($selectionType == REVIEWER_SELECT_CREATE) {
         $userDao =& DAORegistry::getDAO('UserDAO');
         $user = new User();
         $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->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->insertUser($user);
         // Add reviewer interests to interests table
         $interestDao =& DAORegistry::getDAO('InterestDAO');
         $interests = Request::getUserVar('interestsKeywords');
         $interests = array_map('urldecode', $interests);
         // The interests are coming in encoded -- Decode them for DB storage
         if (empty($interests)) {
             $interests = array();
         } elseif (!is_array($interests)) {
             $interests = array($interests);
         }
         $interestDao->insertInterests($interests, $reviewerId, true);
         // 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('sendNotify')) {
             // Send welcome email to user
             import('classes.mail.MailTemplate');
             $mail = new MailTemplate('REVIEWER_REGISTER');
             $mail->setFrom($press->getSetting('contactEmail'), $press->getSetting('contactName'));
             $mail->assignParams(array('username' => $this->getData('username'), 'password' => $password, 'userFullName' => $user->getFullName()));
             $mail->addRecipient($user->getEmail(), $user->getFullName());
             $mail->send();
         }
     } elseif ($selectionType == REVIEWER_SELECT_ENROLL) {
         // Assign a reviewer user group to an existing non-reviewer
         $userId = $this->getData('userId');
         $userGroupId = $this->getData('userGroupId');
         $userGroupId = $this->getData('userGroupId');
         $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
         /* @var $userGroupDao UserGroupDAO */
         $userGroupDao->assignUserToGroup($userId, $userGroupId);
         // Set the reviewerId to the userId to return to the grid
         $reviewerId = $userId;
     } else {
         $reviewerId = $this->getData('reviewerId');
     }
     import('classes.submission.seriesEditor.SeriesEditorAction');
     SeriesEditorAction::addReviewer($submission, $reviewerId, $reviewType, $round, $reviewDueDate, $responseDueDate);
     // Get the reviewAssignment object now that it has been added
     $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
     $reviewAssignment =& $reviewAssignmentDao->getReviewAssignment($submission->getId(), $reviewerId, $round, $reviewType);
     $reviewAssignment->setDateNotified(Core::getCurrentDate());
     $reviewAssignment->setCancelled(0);
     $reviewAssignment->stampModified();
     $reviewAssignmentDao->updateObject($reviewAssignment);
     // Update the review round status if this is the first reviewer added
     $reviewRoundDao =& DAORegistry::getDAO('ReviewRoundDAO');
     $currentReviewRound =& $reviewRoundDao->build($this->getMonographId(), $submission->getCurrentReviewType(), $submission->getCurrentRound());
     if ($currentReviewRound->getStatus() == REVIEW_ROUND_STATUS_PENDING_REVIEWERS) {
         $currentReviewRound->setStatus(REVIEW_ROUND_STATUS_PENDING_REVIEWS);
         $reviewRoundDao->updateObject($currentReviewRound);
     }
     return $reviewAssignment;
 }
 /**
  * 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->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'));
         $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->setInterests($this->getData('interests'), 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;
         }
         $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('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->roleExists($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());
     }
 }
 /**
  * Fulfill a queued payment.
  * @param $queuedPayment QueuedPayment
  * @param $payMethodPluginName string Name of payment plugin.
  * @return mixed Dependent on payment type.
  */
 function fulfillQueuedPayment(&$queuedPayment, $payMethodPluginName = null)
 {
     $returner = false;
     if ($queuedPayment) {
         switch ($queuedPayment->getType()) {
             case PAYMENT_TYPE_MEMBERSHIP:
                 $userDao =& DAORegistry::getDAO('UserDAO');
                 $user =& $userDao->getUser($queuedPayment->getuserId());
                 $userDao->renewMembership($user);
                 $returner = true;
                 break;
             case PAYMENT_TYPE_PURCHASE_SUBSCRIPTION:
                 $subscriptionId = $queuedPayment->getAssocId();
                 $institutionalSubscriptionDao =& DAORegistry::getDAO('InstitutionalSubscriptionDAO');
                 $individualSubscriptionDao =& DAORegistry::getDAO('IndividualSubscriptionDAO');
                 if ($institutionalSubscriptionDao->subscriptionExists($subscriptionId)) {
                     $subscription =& $institutionalSubscriptionDao->getSubscription($subscriptionId);
                     $institutional = true;
                 } else {
                     $subscription =& $individualSubscriptionDao->getSubscription($subscriptionId);
                     $institutional = false;
                 }
                 if (!$subscription || $subscription->getUserId() != $queuedPayment->getUserId() || $subscription->getJournalId() != $queuedPayment->getJournalId()) {
                     // FIXME: Is this supposed to be here?
                     error_log(print_r($subscription, true));
                     return false;
                 }
                 // Update subscription end date now that payment is completed
                 if ($institutional) {
                     // Still requires approval from JM/SM since includes domain and IP ranges
                     import('classes.subscription.InstitutionalSubscription');
                     $subscription->setStatus(SUBSCRIPTION_STATUS_NEEDS_APPROVAL);
                     if ($subscription->isNonExpiring()) {
                         $institutionalSubscriptionDao->updateSubscription($subscription);
                     } else {
                         $institutionalSubscriptionDao->renewSubscription($subscription);
                     }
                     // Notify JM/SM of completed online purchase
                     $journalSettingsDao =& DAORegistry::getDAO('JournalSettingsDAO');
                     if ($journalSettingsDao->getSetting($subscription->getJournalId(), 'enableSubscriptionOnlinePaymentNotificationPurchaseInstitutional')) {
                         import('classes.subscription.SubscriptionAction');
                         SubscriptionAction::sendOnlinePaymentNotificationEmail($subscription, 'SUBSCRIPTION_PURCHASE_INSTL');
                     }
                 } else {
                     import('classes.subscription.IndividualSubscription');
                     $subscription->setStatus(SUBSCRIPTION_STATUS_ACTIVE);
                     if ($subscription->isNonExpiring()) {
                         $individualSubscriptionDao->updateSubscription($subscription);
                     } else {
                         $individualSubscriptionDao->renewSubscription($subscription);
                     }
                     // Notify JM/SM of completed online purchase
                     $journalSettingsDao =& DAORegistry::getDAO('JournalSettingsDAO');
                     if ($journalSettingsDao->getSetting($subscription->getJournalId(), 'enableSubscriptionOnlinePaymentNotificationPurchaseIndividual')) {
                         import('classes.subscription.SubscriptionAction');
                         SubscriptionAction::sendOnlinePaymentNotificationEmail($subscription, 'SUBSCRIPTION_PURCHASE_INDL');
                     }
                 }
                 $returner = true;
                 break;
             case PAYMENT_TYPE_RENEW_SUBSCRIPTION:
                 $subscriptionId = $queuedPayment->getAssocId();
                 $institutionalSubscriptionDao =& DAORegistry::getDAO('InstitutionalSubscriptionDAO');
                 if ($institutionalSubscriptionDao->subscriptionExists($subscriptionId)) {
                     $subscription =& $institutionalSubscriptionDao->getSubscription($subscriptionId);
                     $institutional = true;
                 } else {
                     $individualSubscriptionDao =& DAORegistry::getDAO('IndividualSubscriptionDAO');
                     $subscription =& $individualSubscriptionDao->getSubscription($subscriptionId);
                     $institutional = false;
                 }
                 if (!$subscription || $subscription->getUserId() != $queuedPayment->getUserId() || $subscription->getJournalId() != $queuedPayment->getJournalId()) {
                     // FIXME: Is this supposed to be here?
                     error_log(print_r($subscription, true));
                     return false;
                 }
                 if ($institutional) {
                     $institutionalSubscriptionDao->renewSubscription($subscription);
                     // Notify JM/SM of completed online purchase
                     $journalSettingsDao =& DAORegistry::getDAO('JournalSettingsDAO');
                     if ($journalSettingsDao->getSetting($subscription->getJournalId(), 'enableSubscriptionOnlinePaymentNotificationRenewInstitutional')) {
                         import('classes.subscription.SubscriptionAction');
                         SubscriptionAction::sendOnlinePaymentNotificationEmail($subscription, 'SUBSCRIPTION_RENEW_INSTL');
                     }
                 } else {
                     $individualSubscriptionDao->renewSubscription($subscription);
                     // Notify JM/SM of completed online purchase
                     $journalSettingsDao =& DAORegistry::getDAO('JournalSettingsDAO');
                     if ($journalSettingsDao->getSetting($subscription->getJournalId(), 'enableSubscriptionOnlinePaymentNotificationRenewIndividual')) {
                         import('classes.subscription.SubscriptionAction');
                         SubscriptionAction::sendOnlinePaymentNotificationEmail($subscription, 'SUBSCRIPTION_RENEW_INDL');
                     }
                 }
                 $returner = true;
                 break;
             case PAYMENT_TYPE_FASTTRACK:
                 $articleDao =& DAORegistry::getDAO('ArticleDAO');
                 $article =& $articleDao->getArticle($queuedPayment->getAssocId(), $queuedPayment->getJournalId());
                 $article->setFastTracked(true);
                 $articleDao->updateArticle($article);
                 $returner = true;
                 break;
             case PAYMENT_TYPE_GIFT:
                 $giftId = $queuedPayment->getAssocId();
                 $giftDao =& DAORegistry::getDAO('GiftDAO');
                 $gift =& $giftDao->getGift($giftId);
                 if (!$gift) {
                     return false;
                 }
                 $journalDao =& DAORegistry::getDAO('JournalDAO');
                 $journalId = $gift->getAssocId();
                 $journal =& $journalDao->getById($journalId);
                 if (!$journal) {
                     return false;
                 }
                 // Check if user account corresponding to recipient email exists in the system
                 $userDao =& DAORegistry::getDAO('UserDAO');
                 $roleDao =& DAORegistry::getDAO('RoleDAO');
                 $recipientFirstName = $gift->getRecipientFirstName();
                 $recipientEmail = $gift->getRecipientEmail();
                 $newUserAccount = false;
                 if ($userDao->userExistsByEmail($recipientEmail)) {
                     // User already has account, check if enrolled as reader in journal
                     $user =& $userDao->getUserByEmail($recipientEmail);
                     $userId = $user->getId();
                     if (!$roleDao->userHasRole($journalId, $userId, ROLE_ID_READER)) {
                         // User not enrolled as reader, enroll as reader
                         $role = new Role();
                         $role->setJournalId($journalId);
                         $role->setUserId($userId);
                         $role->setRoleId(ROLE_ID_READER);
                         $roleDao->insertRole($role);
                     }
                 } else {
                     // User does not have an account. Create one and enroll as reader.
                     $recipientLastName = $gift->getRecipientLastName();
                     $username = Validation::suggestUsername($recipientFirstName, $recipientLastName);
                     $password = Validation::generatePassword();
                     $user = new User();
                     $user->setUsername($username);
                     $user->setPassword(Validation::encryptCredentials($username, $password));
                     $user->setFirstName($recipientFirstName);
                     $user->setMiddleName($gift->getRecipientMiddleName());
                     $user->setLastName($recipientLastName);
                     $user->setEmail($recipientEmail);
                     $user->setDateRegistered(Core::getCurrentDate());
                     $userDao->insertUser($user);
                     $userId = $user->getId();
                     $role = new Role();
                     $role->setJournalId($journalId);
                     $role->setUserId($userId);
                     $role->setRoleId(ROLE_ID_READER);
                     $roleDao->insertRole($role);
                     $newUserAccount = true;
                 }
                 // Update gift status (make it redeemable) and add recipient user account reference
                 import('classes.gift.Gift');
                 $gift->setStatus(GIFT_STATUS_NOT_REDEEMED);
                 $gift->setRecipientUserId($userId);
                 $giftDao->updateObject($gift);
                 // Send gift available email to recipient, cc buyer
                 $giftNoteTitle = $gift->getGiftNoteTitle();
                 $buyerFullName = $gift->getBuyerFullName();
                 $giftNote = $gift->getGiftNote();
                 $giftLocale = $gift->getLocale();
                 AppLocale::requireComponents(LOCALE_COMPONENT_APPLICATION_COMMON, $giftLocale);
                 $giftDetails = $gift->getGiftName($giftLocale);
                 $giftJournalName = $journal->getTitle($giftLocale);
                 $giftContactSignature = $journal->getSetting('contactName');
                 import('classes.mail.MailTemplate');
                 $mail = new MailTemplate('GIFT_AVAILABLE', $giftLocale);
                 $mail->setFrom($journal->getSetting('contactEmail'), $journal->getSetting('contactName'));
                 $mail->assignParams(array('giftJournalName' => $giftJournalName, 'giftNoteTitle' => $giftNoteTitle, 'recipientFirstName' => $recipientFirstName, 'buyerFullName' => $buyerFullName, 'giftDetails' => $giftDetails, 'giftNote' => $giftNote, 'giftContactSignature' => $giftContactSignature));
                 $mail->addRecipient($recipientEmail, $user->getFullName());
                 $mail->addCc($gift->getBuyerEmail(), $gift->getBuyerFullName());
                 $mail->send();
                 unset($mail);
                 // Send gift login details to recipient
                 $params = array('giftJournalName' => $giftJournalName, 'recipientFirstName' => $recipientFirstName, 'buyerFullName' => $buyerFullName, 'giftDetails' => $giftDetails, 'giftUrl' => $request->url($journal->getPath(), 'user', 'gifts'), 'username' => $user->getUsername(), 'giftContactSignature' => $giftContactSignature);
                 if ($newUserAccount) {
                     $mail = new MailTemplate('GIFT_USER_REGISTER', $giftLocale);
                     $params['password'] = $password;
                 } else {
                     $mail = new MailTemplate('GIFT_USER_LOGIN', $giftLocale);
                 }
                 $mail->setFrom($journal->getSetting('contactEmail'), $journal->getSetting('contactName'));
                 $mail->assignParams($params);
                 $mail->addRecipient($recipientEmail, $user->getFullName());
                 $mail->send();
                 unset($mail);
                 $returner = true;
                 break;
             case PAYMENT_TYPE_PURCHASE_ARTICLE:
             case PAYMENT_TYPE_PURCHASE_ISSUE:
             case PAYMENT_TYPE_DONATION:
             case PAYMENT_TYPE_SUBMISSION:
             case PAYMENT_TYPE_PUBLICATION:
                 $returner = true;
                 break;
             default:
                 // Invalid payment type
                 assert(false);
         }
     }
     $completedPaymentDao =& DAORegistry::getDAO('OJSCompletedPaymentDAO');
     $completedPayment =& $this->createCompletedPayment($queuedPayment, $payMethodPluginName);
     $completedPaymentDao->insertCompletedPayment($completedPayment);
     $queuedPaymentDao =& DAORegistry::getDAO('QueuedPaymentDAO');
     $queuedPaymentDao->deleteQueuedPayment($queuedPayment->getQueuedPaymentId());
     return $returner;
 }
 /**
  * Save registration.
  */
 function execute()
 {
     $schedConf =& Request::getSchedConf();
     $user =& Request::getUser();
     if (!$user) {
         // New user
         $user = new User();
         $user->setUsername($this->getData('username'));
         $user->setFirstName($this->getData('firstName'));
         $user->setMiddleName($this->getData('middleName'));
         $user->setInitials($this->getData('initials'));
         $user->setLastName($this->getData('lastName'));
         $user->setAffiliation($this->getData('affiliation'));
         $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->setInterests($this->getData('interests'), null);
         // Localized
         $user->setDateRegistered(Core::getCurrentDate());
         $user->setCountry($this->getData('country'));
         $user->setPassword(Validation::encryptCredentials($this->getData('username'), $this->getData('password')));
         $userDao =& DAORegistry::getDAO('UserDAO');
         $userId = $userDao->insertUser($user);
         if (!$userId) {
             return REGISTRATION_FAILED;
         }
         $conference =& Request::getConference();
         $roleDao =& DAORegistry::getDAO('RoleDAO');
         $role = new Role();
         $role->setRoleId(ROLE_ID_READER);
         $role->setSchedConfId($schedConf->getId());
         $role->setConferenceId($conference->getId());
         $role->setUserId($user->getId());
         $roleDao->insertRole($role);
         $sessionManager =& SessionManager::getManager();
         $session =& $sessionManager->getUserSession();
         $session->setSessionVar('username', $user->getUsername());
         // Make sure subsequent requests to Request::getUser work
         Validation::login($this->getData('username'), $this->getData('password'), $reason);
         import('user.form.CreateAccountForm');
         CreateAccountForm::sendConfirmationEmail($user, $this->getData('password'), true);
     }
     // Get the registration type
     $registrationTypeDao =& DAORegistry::getDAO('RegistrationTypeDAO');
     $registrationType =& $registrationTypeDao->getRegistrationType($this->getData('registrationTypeId'));
     if (!$registrationType || $registrationType->getSchedConfId() != $schedConf->getId()) {
         Request::redirect('index');
     }
     import('payment.ocs.OCSPaymentManager');
     $paymentManager =& OCSPaymentManager::getManager();
     if (!$paymentManager->isConfigured()) {
         return REGISTRATION_NO_PAYMENT;
     }
     import('registration.Registration');
     $registration = new Registration();
     $registration->setSchedConfId($schedConf->getId());
     $registration->setUserId($user->getId());
     $registration->setTypeId($this->getData('registrationTypeId'));
     $registration->setSpecialRequests($this->getData('specialRequests') ? $this->getData('specialRequests') : null);
     $registration->setDateRegistered(time());
     $registrationDao =& DAORegistry::getDAO('RegistrationDAO');
     $registrationId = $registrationDao->insertRegistration($registration);
     $registrationOptionDao =& DAORegistry::getDAO('RegistrationOptionDAO');
     $registrationOptions =& $registrationOptionDao->getRegistrationOptionsBySchedConfId($schedConf->getId());
     $registrationOptionIds = (array) $this->getData('registrationOptionId');
     $cost = $registrationType->getCost();
     $registrationOptionCosts = $registrationTypeDao->getRegistrationOptionCosts($this->getData('registrationTypeId'));
     while ($registrationOption =& $registrationOptions->next()) {
         if (in_array($registrationOption->getOptionId(), $registrationOptionIds) && strtotime($registrationOption->getOpeningDate()) < time() && strtotime($registrationOption->getClosingDate()) > time() && $registrationOption->getPublic()) {
             $registrationOptionDao->insertRegistrationOptionAssoc($registrationId, $registrationOption->getOptionId());
             $cost += $registrationOptionCosts[$registrationOption->getOptionId()];
         }
         unset($registrationOption);
     }
     $queuedPayment =& $paymentManager->createQueuedPayment($schedConf->getConferenceId(), $schedConf->getId(), QUEUED_PAYMENT_TYPE_REGISTRATION, $user->getId(), $registrationId, $cost, $registrationType->getCurrencyCodeAlpha());
     $queuedPaymentId = $paymentManager->queuePayment($queuedPayment, time() + 60 * 60 * 24 * 30);
     // 30 days to complete
     if ($cost == 0) {
         $paymentManager->fulfillQueuedPayment($queuedPaymentId, $queuedPayment);
         return REGISTRATION_FREE;
     } else {
         $paymentManager->displayPaymentForm($queuedPaymentId, $queuedPayment);
     }
     return REGISTRATION_SUCCESSFUL;
 }
 /**
  * Reset a user's password
  * @param $args array first param contains the username of the user whose password is to be reset
  */
 function resetPassword($args, &$request)
 {
     $this->validate();
     $this->setupTemplate($request);
     $site =& $request->getSite();
     $oneStepReset = $site->getSetting('oneStepReset') ? true : false;
     $username = isset($args[0]) ? $args[0] : null;
     $userDao =& DAORegistry::getDAO('UserDAO');
     $confirmHash = $request->getUserVar('confirm');
     if ($username == null || ($user =& $userDao->getByUsername($username)) == null) {
         $request->redirect(null, null, 'lostPassword');
     }
     $templateMgr =& TemplateManager::getManager();
     if (!Validation::verifyPasswordResetHash($user->getId(), $confirmHash)) {
         $templateMgr->assign('errorMsg', 'user.login.lostPassword.invalidHash');
         $templateMgr->assign('backLink', $request->url(null, null, 'lostPassword'));
         $templateMgr->assign('backLinkLabel', 'user.login.resetPassword');
         $templateMgr->display('common/error.tpl');
     } else {
         if (!$oneStepReset) {
             // Reset password
             $newPassword = Validation::generatePassword();
             if ($user->getAuthId()) {
                 $authDao =& DAORegistry::getDAO('AuthSourceDAO');
                 $auth =& $authDao->getPlugin($user->getAuthId());
             }
             if (isset($auth)) {
                 $auth->doSetUserPassword($user->getUsername(), $newPassword);
                 $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword()));
                 // Used for PW reset hash only
             } else {
                 $user->setPassword(Validation::encryptCredentials($user->getUsername(), $newPassword));
             }
             $user->setMustChangePassword(1);
             $userDao->updateObject($user);
             // Send email with new password
             import('classes.mail.MailTemplate');
             $mail = new MailTemplate('PASSWORD_RESET');
             $this->_setMailFrom($request, $mail, $site);
             $mail->assignParams(array('username' => $user->getUsername(), 'password' => $newPassword, 'siteTitle' => $site->getLocalizedTitle()));
             $mail->addRecipient($user->getEmail(), $user->getFullName());
             $mail->send();
             $templateMgr->assign('pageTitle', 'user.login.resetPassword');
             $templateMgr->assign('message', 'user.login.lostPassword.passwordSent');
             $templateMgr->assign('backLink', $request->url(null, $request->getRequestedPage()));
             $templateMgr->assign('backLinkLabel', 'user.login');
             $templateMgr->display('common/message.tpl');
         } else {
             import('classes.user.form.LoginChangePasswordForm');
             $passwordForm = new LoginChangePasswordForm($confirmHash);
             $passwordForm->initData();
             if (isset($args[0])) {
                 $passwordForm->setData('username', $username);
             }
             $passwordForm->display();
         }
     }
 }
Beispiel #20
0
 /**
  * Reset a user's password
  * @param $args array first param contains the username of the user whose password is to be reset
  */
 function resetPassword($args, $request)
 {
     $this->setupTemplate($request);
     $username = isset($args[0]) ? $args[0] : null;
     $userDao = DAORegistry::getDAO('UserDAO');
     $confirmHash = $request->getUserVar('confirm');
     if ($username == null || ($user = $userDao->getByUsername($username)) == null) {
         $request->redirect(null, null, 'lostPassword');
     }
     $templateMgr = TemplateManager::getManager($request);
     if (!Validation::verifyPasswordResetHash($user->getId(), $confirmHash)) {
         $templateMgr->assign(array('errorMsg' => 'user.login.lostPassword.invalidHash', 'backLink' => $request->url(null, null, 'lostPassword'), 'backLinkLabel' => 'user.login.resetPassword'));
         $templateMgr->display('frontend/pages/error.tpl');
     } else {
         // Reset password
         $newPassword = Validation::generatePassword();
         if ($user->getAuthId()) {
             $authDao = DAORegistry::getDAO('AuthSourceDAO');
             $auth = $authDao->getPlugin($user->getAuthId());
         }
         if (isset($auth)) {
             $auth->doSetUserPassword($user->getUsername(), $newPassword);
             $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword()));
             // Used for PW reset hash only
         } else {
             $user->setPassword(Validation::encryptCredentials($user->getUsername(), $newPassword));
         }
         $user->setMustChangePassword(1);
         $userDao->updateObject($user);
         // Send email with new password
         $site = $request->getSite();
         import('lib.pkp.classes.mail.MailTemplate');
         $mail = new MailTemplate('PASSWORD_RESET');
         $this->_setMailFrom($request, $mail, $site);
         $mail->assignParams(array('username' => $user->getUsername(), 'password' => $newPassword, 'siteTitle' => $site->getLocalizedTitle()));
         $mail->addRecipient($user->getEmail(), $user->getFullName());
         $mail->send();
         $templateMgr->assign(array('pageTitle' => 'user.login.resetPassword', 'message' => 'user.login.lostPassword.passwordSent', 'backLink' => $request->url(null, $request->getRequestedPage()), 'backLinkLabel' => 'user.login'));
         $templateMgr->display('frontend/pages/message.tpl');
     }
 }
Beispiel #21
0
 /**
  * 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'));
     $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->setCountry($this->getData('country'));
     $user->setBiography($this->getData('biography'), null);
     // Localized
     $user->setInterests($this->getData('interests'), null);
     // Localized
     $user->setGossip($this->getData('gossip'), null);
     // Localized
     $user->setMustChangePassword($this->getData('mustChangePassword') ? 1 : 0);
     $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->setDateRegistered(Core::getCurrentDate());
     $userId = $userDao->insertUser($user);
     $roleDao =& DAORegistry::getDAO('RoleDAO');
     $schedConf =& Request::getSchedConf();
     $role = new Role();
     $role->setConferenceId($schedConf->getConferenceId());
     $role->setSchedConfId($schedConf->getId());
     $role->setUserId($userId);
     $role->setRoleId(ROLE_ID_REVIEWER);
     $roleDao->insertRole($role);
     if ($sendNotify) {
         // Send welcome email to user
         import('mail.MailTemplate');
         $mail = new MailTemplate('USER_REGISTER');
         $mail->setFrom($schedConf->getSetting('contactEmail'), $schedConf->getSetting('contactName'));
         $mail->assignParams(array('username' => $this->getData('username'), 'password' => $password));
         $mail->addRecipient($user->getEmail(), $user->getFullName());
         $mail->send();
     }
     return $userId;
 }
    /**
     * 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;
    }
Beispiel #23
0
 /**
  * Check if a user's credentials are valid.
  * @param $username string username
  * @param $password string unencrypted password
  * @return boolean
  */
 function checkCredentials($username, $password)
 {
     $userDao =& DAORegistry::getDAO('UserDAO');
     $user =& $userDao->getUserByUsername($username, false);
     $valid = false;
     if (isset($user)) {
         if ($user->getAuthId()) {
             $authDao =& DAORegistry::getDAO('AuthSourceDAO');
             $auth =& $authDao->getPlugin($user->getAuthId());
         }
         if (isset($auth)) {
             $valid = $auth->authenticate($username, $password);
         } else {
             $valid = $user->getPassword() === Validation::encryptCredentials($username, $password);
         }
     }
     return $valid;
 }
Beispiel #24
0
 /**
  * Import users and roles.
  */
 function importUsers()
 {
     if ($this->hasOption('verbose')) {
         printf("Importing users\n");
     }
     $userDao =& DAORegistry::getDAO('UserDAO');
     $roleDao =& DAORegistry::getDAO('RoleDAO');
     $notifyDao =& DAORegistry::getDAO('NotificationStatusDAO');
     $result =& $this->importDao->retrieve('SELECT *, DECODE(chPassword, ?) AS chPassword FROM tblusers ORDER BY nUserID', $this->journalConfigInfo['chPasswordSalt']);
     while (!$result->EOF) {
         $row =& $result->fields;
         $chFirstName = Core::cleanVar($row['chFirstName']);
         $chMiddleInitial = Core::cleanVar($row['chMiddleInitial']);
         $chSurname = Core::cleanVar($row['chSurname']);
         $initials = substr($chFirstName, 0, 1) . (empty($chMiddleInitial) ? '' : substr($chMiddleInitial, 0, 1)) . substr($chSurname, 0, 1);
         $interests = '';
         if ($row['fkEditorID']) {
             $tmpResult =& $this->importDao->retrieve('SELECT chInitials, nEditorRole FROM tbleditors WHERE nEditorID = ?', $row['fkEditorID']);
             $initials = Core::cleanVar($tmpResult->fields[0]);
             $editorRole = Core::cleanVar($tmpResult->fields[1]);
             $tmpResult->Close();
         }
         if ($row['fkReviewerID']) {
             $tmpResult =& $this->importDao->retrieve('SELECT chInterests FROM tblreviewers WHERE nReviewerID = ?', $row['fkReviewerID']);
             $interests = Core::cleanVar($tmpResult->fields[0]);
             $tmpResult->Close();
         }
         // Get username, email and transliterate to ASCII
         import('core.Transcoder');
         $trans =& new Transcoder('UTF-8', 'ASCII', true);
         $username = $trans->trans(Core::cleanVar($row['chUsername']));
         $email = $trans->trans(Core::cleanVar($row['chEmail']));
         // Check for existing user with this username
         $user = $userDao->getUserByUsername($username);
         $existingUser = $user != null;
         if (!isset($user)) {
             // Create new user
             $user =& new User();
             $user->setUsername($username);
             $user->setPassword(Validation::encryptCredentials($username, Core::cleanVar($row['chPassword'])));
             $user->setFirstName(Core::cleanVar($row['chFirstName']));
             $user->setMiddleName(Core::cleanVar($row['chMiddleInitial']));
             $user->setInitials(Core::cleanVar($initials));
             $user->setLastName(Core::cleanVar($row['chSurname']));
             $user->setAffiliation(Core::cleanVar($row['chAffiliation']));
             $user->setEmail($email);
             $user->setPhone(Core::cleanVar($row['chPhone']));
             $user->setFax(Core::cleanVar($row['chFax']));
             $user->setMailingAddress(Core::cleanVar($row['chMailAddr']));
             $user->setBiography(Core::cleanVar($row['chBiography']), Locale::getLocale());
             $user->setInterests(Core::cleanVar($interests), Locale::getLocale());
             $user->setLocales(array());
             $user->setDateRegistered($row['dtDateSignedUp']);
             $user->setDateLastLogin($row['dtDateSignedUp']);
             $user->setMustChangePassword(0);
             $user->setDisabled(0);
             $otherUser =& $userDao->getUserByEmail($email);
             if ($otherUser !== null) {
                 // User exists with this email -- munge it to make unique
                 $user->setEmail('ojs-' . $username . '+' . $email);
                 $this->conflicts[] = array(&$otherUser, &$user);
             }
             unset($otherUser);
             $userDao->insertUser($user);
         }
         $userId = $user->getUserId();
         if ($row['bNotify']) {
             if ($existingUser) {
                 // Just in case
                 $notifyDao->setJournalNotifications($this->journalId, $userId, 0);
             }
             $notifyDao->setJournalNotifications($this->journalId, $userId, 1);
         }
         if ($row['fkEditorID']) {
             $role =& new Role();
             $role->setJournalId($this->journalId);
             $role->setUserId($userId);
             switch ($editorRole) {
                 case 0:
                     $role->setRoleId(ROLE_ID_EDITOR);
                     break;
                 case 1:
                     $role->setRoleId(ROLE_ID_SECTION_EDITOR);
                     break;
                 case 2:
                     $role->setRoleId(ROLE_ID_JOURNAL_MANAGER);
                     break;
                 case 3:
                     $role->setRoleId(ROLE_ID_LAYOUT_EDITOR);
                     $this->journalLayoutUserId = $userId;
                     // Assume one LE per journal, as per OJS 1.x semantics
                     break;
             }
             if (!$existingUser || !$roleDao->roleExists($role->getJournalId(), $role->getUserId(), $role->getRoleId())) {
                 $roleDao->insertRole($role);
             }
         }
         if ($row['fkAuthorID']) {
             $role =& new Role();
             $role->setJournalId($this->journalId);
             $role->setUserId($userId);
             $role->setRoleId(ROLE_ID_AUTHOR);
             if (!$existingUser || !$roleDao->roleExists($role->getJournalId(), $role->getUserId(), $role->getRoleId())) {
                 $roleDao->insertRole($role);
             }
         }
         if ($row['fkReviewerID']) {
             $role =& new Role();
             $role->setJournalId($this->journalId);
             $role->setUserId($userId);
             $role->setRoleId(ROLE_ID_REVIEWER);
             if (!$existingUser || !$roleDao->roleExists($role->getJournalId(), $role->getUserId(), $role->getRoleId())) {
                 $roleDao->insertRole($role);
             }
         }
         if ($row['fkCopyEdID']) {
             $role =& new Role();
             $role->setJournalId($this->journalId);
             $role->setUserId($userId);
             $role->setRoleId(ROLE_ID_COPYEDITOR);
             if (!$existingUser || !$roleDao->roleExists($role->getJournalId(), $role->getUserId(), $role->getRoleId())) {
                 $roleDao->insertRole($role);
             }
         }
         if ($row['fkProofID']) {
             $role =& new Role();
             $role->setJournalId($this->journalId);
             $role->setUserId($userId);
             $role->setRoleId(ROLE_ID_PROOFREADER);
             if (!$existingUser || !$roleDao->roleExists($role->getJournalId(), $role->getUserId(), $role->getRoleId())) {
                 $roleDao->insertRole($role);
             }
         }
         if ($row['fkReaderID']) {
             $role =& new Role();
             $role->setJournalId($this->journalId);
             $role->setUserId($userId);
             $role->setRoleId(ROLE_ID_READER);
             if (!$existingUser || !$roleDao->roleExists($role->getJournalId(), $role->getUserId(), $role->getRoleId())) {
                 $roleDao->insertRole($role);
             }
         }
         $this->userMap[$row['nUserID']] = $userId;
         $this->userCount++;
         $result->MoveNext();
         unset($user);
     }
     $result->Close();
 }
 /**
  * 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;
 }
 /**
  * Register a new user.
  */
 function execute()
 {
     $userDao =& DAORegistry::getDAO('UserDAO');
     $journal =& Request::getJournal();
     if (isset($this->userId)) {
         $user =& $userDao->getUser($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->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 (Locale::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();
         // EL on March 13th 2013
         // If this is used, it should be totally modified
         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('supportEmail'), $journal->getSetting('supportName'));
             $mail->assignParams(array('username' => $this->getData('username'), 'password' => String::substr($this->getData('password'), 0, 30), 'supportName' => $journal->getSetting('supportName'), 'userFullName' => $user->getFullName()));
             $mail->addRecipient($user->getEmail(), $user->getFullName());
             $mail->send();
         }
     }
     // Add reviewing interests to interests table
     $interestDao =& DAORegistry::getDAO('InterestDAO');
     $interests = is_array(Request::getUserVar('interestsKeywords')) ? Request::getUserVar('interestsKeywords') : array();
     if (is_array($interests)) {
         $interests = array_map('urldecode', $interests);
         // The interests are coming in encoded -- Decode them for DB storage
         $interestTextOnly = Request::getUserVar('interests');
         if (!empty($interestsTextOnly)) {
             // If JS is disabled, this will be the input to read
             $interestsTextOnly = explode(",", $interestTextOnly);
         } else {
             $interestsTextOnly = null;
         }
         if ($interestsTextOnly && !isset($interests)) {
             $interests = $interestsTextOnly;
         } elseif (isset($interests) && !is_array($interests)) {
             $interests = array($interests);
         }
         $interestDao->insertInterests($interests, $userId, true);
     }
 }
 /**
  * Register a new user.
  * @return userId int
  * Last modified: EL on February 22th 2013
  */
 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->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);
     $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 (Locale::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->setDateRegistered(Core::getCurrentDate());
     $userId = $userDao->insertUser($user);
     // Add reviewing interests to interests table
     $interestDao =& DAORegistry::getDAO('InterestDAO');
     $interests = is_array(Request::getUserVar('interestsKeywords')) ? Request::getUserVar('interestsKeywords') : array();
     if (is_array($interests)) {
         $interests = array_map('urldecode', $interests);
         // The interests are coming in encoded -- Decode them for DB storage
         $interestTextOnly = Request::getUserVar('interests');
         if (!empty($interestsTextOnly)) {
             // If JS is disabled, this will be the input to read
             $interestsTextOnly = explode(",", $interestTextOnly);
         } else {
             $interestsTextOnly = null;
         }
         if ($interestsTextOnly && !isset($interests)) {
             $interests = $interestsTextOnly;
         } elseif (isset($interests) && !is_array($interests)) {
             $interests = array($interests);
         }
         $interestDao->insertInterests($interests, $user->getId(), true);
     }
     $interestDao->insertInterests($interests, $user->getId(), true);
     $roleDao =& DAORegistry::getDAO('RoleDAO');
     $journal =& Request::getJournal();
     $ercStatus = $this->getData('ercStatus');
     if ($ercStatus == "Secretary") {
         $role = new Role();
         $role->setJournalId($journal->getId());
         $role->setUserId($userId);
         $role->setRoleId(ROLE_ID_SECTION_EDITOR);
         $roleDao->insertRole($role);
         $sectionEditorsDao =& DAORegistry::getDAO('SectionEditorsDAO');
         $sectionEditorsDao->insertEditor($journal->getId(), $this->sectionId, $userId, 1, 1);
     } elseif ($ercStatus == "Chair" || $ercStatus == "Vice-Chair" || $ercStatus == "Member") {
         $role = new Role();
         $role->setJournalId($journal->getId());
         $role->setUserId($userId);
         $role->setRoleId(ROLE_ID_REVIEWER);
         $roleDao->insertRole($role);
         $ercReviewersDao =& DAORegistry::getDAO('ErcReviewersDAO');
         if ($ercStatus == "Chair") {
             $ercReviewersDao->insertReviewer($journal->getId(), $this->sectionId, $userId, 1);
         } elseif ($ercStatus == "Vice-Chair") {
             $ercReviewersDao->insertReviewer($journal->getId(), $this->sectionId, $userId, 2);
         }
         if ($ercStatus == "Member") {
             $ercReviewersDao->insertReviewer($journal->getId(), $this->sectionId, $userId, 3);
         }
     }
     if ($sendNotify) {
         $sectionDao =& DAORegistry::getDAO('SectionDAO');
         $erc =& $sectionDao->getSection($this->sectionId);
         $thisUser =& Request::getUser();
         // Send welcome email to user
         import('classes.mail.MailTemplate');
         $mail = new MailTemplate('COMMITTEE_REGISTER');
         $mail->setFrom($journal->getSetting('contactEmail'), $journal->getSetting('contactName'));
         $mail->assignParams(array('username' => $this->getData('username'), 'password' => $password, 'userFullName' => $user->getFullName(), 'ercStatus' => $ercStatus, 'ercTitle' => $erc->getLocalizedTitle(), 'editProfile' => Request::url(null, 'user', 'profile'), 'secretaryFullName' => $thisUser->getFullName(), 'secretaryFunctions' => $thisUser->getErcFunction($this->sectionId)));
         $mail->addRecipient($user->getEmail(), $user->getFullName());
         $mail->send();
     }
     return $userId;
 }
Beispiel #28
0
 /**
  * Import papers (including metadata and files).
  */
 function importPapers()
 {
     if ($this->hasOption('verbose')) {
         printf("Importing papers\n");
     }
     import('classes.file.PaperFileManager');
     import('classes.search.PaperSearchIndex');
     $userDao =& DAORegistry::getDAO('UserDAO');
     $roleDao =& DAORegistry::getDAO('RoleDAO');
     $trackDao =& DAORegistry::getDAO('TrackDAO');
     $paperDao =& DAORegistry::getDAO('PaperDAO');
     $publishedPaperDao =& DAORegistry::getDAO('PublishedPaperDAO');
     $galleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
     $unassignedTrackId = null;
     $result =& $this->importDao->retrieve('SELECT * FROM papers ORDER by id');
     while (!$result->EOF) {
         $row =& $result->fields;
         $schedConf =& $this->schedConfMap[$row['cf']];
         $schedConfId = $schedConf->getId();
         // Bring in the primary user for this paper.
         $user = $userDao->getUserByUsername(Core::cleanVar($row['login']));
         if (!$user) {
             unset($user);
             $user = new User();
             $user->setUsername(Core::cleanVar($row['login']));
             $user->setFirstName(Core::cleanVar($row['first_name']));
             $user->setLastName(Core::cleanVar($row['surname']));
             $user->setAffiliation(Core::cleanVar($row['affiliation']), Locale::getLocale());
             $user->setEmail(Core::cleanVar($row['email']));
             $user->setUrl(Core::cleanVar($row['url']));
             $user->setBiography(Core::cleanVar($row['bio']), Locale::getLocale());
             $user->setLocales(array());
             $user->setDateRegistered($row['created']);
             $user->setDateLastLogin($row['created']);
             $user->setMustChangePassword(1);
             $password = Validation::generatePassword();
             $user->setPassword(Validation::encryptCredentials($user->getUsername(), $password));
             if ($this->hasOption('emailUsers')) {
                 import('classes.mail.MailTemplate');
                 $mail = new MailTemplate('USER_REGISTER');
                 $mail->setFrom($schedConf->getSetting('contactEmail'), $schedConf->getSetting('contactName'));
                 $mail->assignParams(array('username' => $user->getUsername(), 'password' => $password, 'conferenceName' => $schedConf->getFullTitle()));
                 $mail->addRecipient($user->getEmail(), $user->getFullName());
                 $mail->send();
             }
             $user->setDisabled(0);
             $otherUser =& $userDao->getUserByEmail(Core::cleanVar($row['email']));
             if ($otherUser !== null) {
                 // User exists with this email -- munge it to make unique
                 $user->setEmail('ocs-' . Core::cleanVar($row['login']) . '+' . Core::cleanVar($row['email']));
                 $this->conflicts[] = array(&$otherUser, &$user);
             }
             unset($otherUser);
             $userDao->insertUser($user);
             // Make this user a author
             $role = new Role();
             $role->setSchedConfId($schedConf->getId());
             $role->setConferenceId($schedConf->getConferenceId());
             $role->setUserId($user->getId());
             $role->setRoleId(ROLE_ID_AUTHOR);
             $roleDao->insertRole($role);
             unset($role);
         }
         $userId = $user->getId();
         // Bring in the basic entry for the paper
         $paper = new Paper();
         $paper->setUserId($userId);
         $paper->setLocale(Locale::getPrimaryLocale());
         $paper->setSchedConfId($schedConfId);
         $oldTrackId = $row['primary_track_id'];
         if (!$oldTrackId || !isset($this->trackMap[$oldTrackId])) {
             $oldTrackId = $row['secondary_track_id'];
         }
         if (!$oldTrackId || !isset($this->trackMap[$oldTrackId])) {
             if (!$unassignedTrackId) {
                 // Create an "Unassigned" track to use for submissions
                 // that didn't have a track in OCS 1.x.
                 $track = new Track();
                 $track->setSchedConfId($schedConf->getId());
                 $track->setTitle('UNASSIGNED', Locale::getLocale());
                 $track->setSequence(REALLY_BIG_NUMBER);
                 $track->setDirectorRestricted(1);
                 $track->setMetaReviewed(1);
                 $unassignedTrackId = $trackDao->insertTrack($track);
             }
             $newTrackId = $unassignedTrackId;
         } else {
             $newTrackId = $this->trackMap[$oldTrackId];
         }
         $paper->setTrackId($newTrackId);
         $paper->setTitle(Core::cleanVar($row['title']), Locale::getLocale());
         $paper->setAbstract(Core::cleanVar($row['abstract']), Locale::getLocale());
         $paper->setDiscipline(Core::cleanVar($row['discipline']), Locale::getLocale());
         $paper->setSponsor(Core::cleanVar($row['sponsor']), Locale::getLocale());
         $paper->setSubject(Core::cleanVar($row['topic']), Locale::getLocale());
         $paper->setLanguage(Core::cleanVar($row['language']));
         $paper->setDateSubmitted($row['created']);
         $paper->setDateStatusModified($row['timestamp']);
         // $paper->setTypeConst($row['present_format'] == 'multiple' ? SUBMISSION_TYPE_PANEL : SUBMISSION_TYPE_SINGLE); FIXME
         $paper->setCurrentRound(REVIEW_ROUND_ABSTRACT);
         $paper->setSubmissionProgress(0);
         $paper->setPages('');
         // Bring in authors
         $firstNames = split("\n", Core::cleanVar($row['first_name'] . "\n" . $row['add_first_names']));
         $lastNames = split("\n", Core::cleanVar($row['surname'] . "\n" . $row['add_surnames']));
         $emails = split("\n", Core::cleanVar($row['email'] . "\n" . $row['add_emails']));
         $affiliations = split("\n", Core::cleanVar($row['affiliation'] . "\n" . $row['add_affiliations']));
         $urls = split("\n", Core::cleanVar($row['url'] . "\n" . $row['add_urls']));
         foreach ($emails as $key => $email) {
             if (empty($email)) {
                 continue;
             }
             $author = new Author();
             $author->setEmail($email);
             $author->setFirstName($firstNames[$key]);
             $author->setLastName($lastNames[$key]);
             $author->setAffiliation($affiliations[$key], Locale::getLocale());
             @$author->setUrl($urls[$key]);
             // Suppress warnings from inconsistent OCS 1.x data
             $author->setPrimaryContact($key == 0 ? 1 : 0);
             $paper->addAuthor($author);
             unset($author);
         }
         switch ($row['accepted']) {
             case 'true':
                 $paper->setStatus(STATUS_PUBLISHED);
                 $paperId = $paperDao->insertPaper($paper);
                 $publishedPaper = new PublishedPaper();
                 $publishedPaper->setPaperId($paperId);
                 $publishedPaper->setSchedConfId($schedConfId);
                 $publishedPaper->setDatePublished(Core::getCurrentDate());
                 $publishedPaper->setSeq(REALLY_BIG_NUMBER);
                 $publishedPaper->setViews(0);
                 $publishedPaperDao->insertPublishedPaper($publishedPaper);
                 $publishedPaperDao->resequencePublishedPapers($paper->getTrackId(), $schedConfId);
                 break;
             case 'reject':
                 $paper->setStatus(STATUS_DECLINED);
                 $paperId = $paperDao->insertPaper($paper);
                 break;
             default:
                 $paper->setStatus(STATUS_QUEUED);
                 $paperId = $paperDao->insertPaper($paper);
         }
         $this->paperMap[$row['id']] =& $paper;
         $paperFileManager = new PaperFileManager($paperId);
         if (!empty($row['paper']) && $row['paper'] != 'PDF') {
             $format = 'text/html';
             $extension = $paperFileManager->getDocumentExtension($format);
             $fileId = $paperFileManager->writeSubmissionFile('migratedFile' . $extension, $row['paper'], $format);
             $paper->setSubmissionFileId($fileId);
             $paperDao->updatePaper($paper);
             $fileId = $paperFileManager->writePublicFile('migratedGalley' . $extension, $row['paper'], $format);
             PaperSearchIndex::updateFileIndex($paperId, PAPER_SEARCH_GALLEY_FILE, $fileId);
             if (strstr($format, 'html')) {
                 $galley = new PaperHTMLGalley();
                 $galley->setLabel('HTML');
             } else {
                 $galley = new PaperGalley();
                 switch ($format) {
                     case 'application/pdf':
                         $galley->setLabel('PDF');
                         break;
                     case 'application/postscript':
                         $galley->setLabel('PostScript');
                         break;
                     case 'application/msword':
                         $galley->setLabel('Word');
                         break;
                     case 'text/xml':
                         $galley->setLabel('XML');
                         break;
                     case 'application/powerpoint':
                         $galley->setLabel('Slideshow');
                         break;
                     default:
                         $galley->setLabel('Untitled');
                         break;
                 }
             }
             $galley->setLocale(Locale::getLocale());
             $galley->setPaperId($paperId);
             $galley->setFileId($fileId);
             $galleyDao->insertGalley($galley);
             unset($galley);
         } elseif ($row['paper'] == 'PDF') {
             $fileId = $paperFileManager->copySubmissionFile($this->importPath . '/papers/' . $row['pdf'], 'application/pdf');
             $paper->setSubmissionFileId($fileId);
             $paperDao->updatePaper($paper);
             $fileId = $paperFileManager->copyPublicFile($this->importPath . '/papers/' . $row['pdf'], 'application/pdf');
             PaperSearchIndex::updateFileIndex($paperId, PAPER_SEARCH_GALLEY_FILE, $fileId);
             $galley = new PaperGalley();
             $galley->setLabel('PDF');
             $galley->setLocale(Locale::getLocale());
             $galley->setPaperId($paperId);
             $galley->setFileId($fileId);
             $galleyDao->insertGalley($galley);
             unset($galley);
         }
         // FIXME: The following fields from OCS 1.x are UNUSED:
         // program_insert approach coverage format relation appendix_names appendix_dates
         // appendix appendix_pdf secondary_track_id multiple_* restrict_access paper_email
         // delete_paper comment_email
         unset($user);
         unset($paper);
         unset($schedConf);
         unset($paperFileManager);
         $result->MoveNext();
     }
     $result->Close();
 }
 /**
  * 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;
 }
Beispiel #30
0
 /**
  * Create initial required data.
  * @return boolean
  */
 function createData()
 {
     // Add initial site data
     $locale = $this->getParam('locale');
     $siteDao =& DAORegistry::getDAO('SiteDAO', $this->dbconn);
     $site = new Site();
     $site->setRedirect(0);
     $site->setMinPasswordLength(INSTALLER_DEFAULT_MIN_PASSWORD_LENGTH);
     $site->setPrimaryLocale($locale);
     $site->setInstalledLocales($this->installedLocales);
     $site->setSupportedLocales($this->installedLocales);
     if (!$siteDao->insertSite($site)) {
         $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
         return false;
     }
     $siteSettingsDao =& DAORegistry::getDAO('SiteSettingsDAO');
     $siteSettingsDao->updateSetting('title', array($locale => __(INSTALLER_DEFAULT_SITE_TITLE)), null, true);
     $siteSettingsDao->updateSetting('contactName', array($locale => __(INSTALLER_DEFAULT_SITE_TITLE)), null, true);
     $siteSettingsDao->updateSetting('contactEmail', array($locale => $this->getParam('adminEmail')), null, true);
     // Add initial site administrator user
     $userDao =& DAORegistry::getDAO('UserDAO', $this->dbconn);
     $user = new User();
     $user->setUsername($this->getParam('adminUsername'));
     $user->setPassword(Validation::encryptCredentials($this->getParam('adminUsername'), $this->getParam('adminPassword'), $this->getParam('encryption')));
     $user->setFirstName($user->getUsername());
     $user->setLastName('');
     $user->setEmail($this->getParam('adminEmail'));
     if (!$userDao->insertUser($user)) {
         $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
         return false;
     }
     $roleDao =& DAORegistry::getDao('RoleDAO', $this->dbconn);
     $role = new Role();
     $role->setConferenceId(0);
     $role->setUserId($user->getId());
     $role->setRoleId(ROLE_ID_SITE_ADMIN);
     if (!$roleDao->insertRole($role)) {
         $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
         return false;
     }
     // Install email template list and data for each locale
     $emailTemplateDao =& DAORegistry::getDAO('EmailTemplateDAO');
     $emailTemplateDao->installEmailTemplates($emailTemplateDao->getMainEmailTemplatesFilename());
     foreach ($this->installedLocales as $locale) {
         $emailTemplateDao->installEmailTemplateData($emailTemplateDao->getMainEmailTemplateDataFilename($locale));
     }
     // Add initial plugin data to versions table
     $versionDao =& DAORegistry::getDAO('VersionDAO');
     import('site.VersionCheck');
     $categories = PluginRegistry::getCategories();
     foreach ($categories as $category) {
         PluginRegistry::loadCategory($category, true);
         $plugins = PluginRegistry::getPlugins($category);
         foreach ($plugins as $plugin) {
             $versionFile = $plugin->getPluginPath() . '/version.xml';
             if (FileManager::fileExists($versionFile)) {
                 $versionInfo =& VersionCheck::parseVersionXML($versionFile);
                 $pluginVersion = $versionInfo['version'];
                 $pluginVersion->setCurrent(1);
                 $versionDao->insertVersion($pluginVersion);
             } else {
                 $pluginVersion = new Version();
                 $pluginVersion->setMajor(1);
                 $pluginVersion->setMinor(0);
                 $pluginVersion->setRevision(0);
                 $pluginVersion->setBuild(0);
                 $pluginVersion->setDateInstalled(Core::getCurrentDate());
                 $pluginVersion->setCurrent(1);
                 $pluginVersion->setProductType('plugins.' . $category);
                 $pluginVersion->setProduct(basename($plugin->getPluginPath()));
                 $versionDao->insertVersion($pluginVersion);
             }
         }
     }
     return true;
 }