Ejemplo n.º 1
0
 /**
  * Add a new event log entry with the specified parameters
  * @param $request object
  * @param $submission object
  * @param $eventType int
  * @param $messageKey string
  * @param $params array optional
  * @return object SubmissionLogEntry iff the event was logged
  */
 static function logEvent($request, $submission, $eventType, $messageKey, $params = array())
 {
     // Create a new entry object
     $submissionEventLogDao = DAORegistry::getDAO('SubmissionEventLogDAO');
     $entry = $submissionEventLogDao->newDataObject();
     // Set implicit parts of the log entry
     $entry->setDateLogged(Core::getCurrentDate());
     $entry->setIPAddress($request->getRemoteAddr());
     if (Validation::isLoggedInAs()) {
         // If user is logged in as another user log with real userid
         $sessionManager = SessionManager::getManager();
         $session = $sessionManager->getUserSession();
         $userId = $session->getSessionVar('signedInAs');
         if ($userId) {
             $entry->setUserId($userId);
         }
     } else {
         $user = $request->getUser();
         if ($user) {
             $entry->setUserId($user->getId());
         }
     }
     $entry->setSubmissionId($submission->getId());
     // Set explicit parts of the log entry
     $entry->setEventType($eventType);
     $entry->setMessage($messageKey);
     $entry->setParams($params);
     $entry->setIsTranslated(0);
     // Legacy for old entries. All messages now use locale keys.
     // Insert the resulting object
     $submissionEventLogDao->insertObject($entry);
     return $entry;
 }
Ejemplo n.º 2
0
/**
 * Handle a new request.
 */
function handleRequest()
{
    if (!Config::getVar('general', 'installed') && pageRequiresInstall()) {
        // Redirect to installer if application has not been installed
        Request::redirect(null, 'install');
    }
    // Determine the handler for this request
    $page = Request::getRequestedPage();
    $op = Request::getRequestedOp();
    $sourceFile = sprintf('pages/%s/index.php', $page);
    // If a hook has been registered to handle this page, give it the
    // opportunity to load required resources and set HANDLER_CLASS.
    if (!HookRegistry::call('LoadHandler', array(&$page, &$op, &$sourceFile))) {
        if (file_exists($sourceFile)) {
            require $sourceFile;
        } else {
            require 'pages/index/index.php';
        }
    }
    if (!defined('SESSION_DISABLE_INIT')) {
        // Initialize session
        $sessionManager =& SessionManager::getManager();
        $session =& $sessionManager->getUserSession();
    }
    $methods = array_map('strtolower', get_class_methods(HANDLER_CLASS));
    if (in_array(strtolower($op), $methods)) {
        // Call a specific operation
        call_user_func(array(HANDLER_CLASS, $op), Request::getRequestedArgs());
    } else {
        // Call the selected handler's index operation
        call_user_func(array(HANDLER_CLASS, 'index'), Request::getRequestedArgs());
    }
}
 /**
  * Gathers the state of a given cell given a $row/$column combination
  * @param $row GridRow
  * @param $column GridColumn
  * @return string
  */
 function getCellState(&$row, &$column)
 {
     $element =& $row->getData();
     $columnId = $column->getId();
     assert(is_a($element, 'DataObject') && !empty($columnId));
     switch ($columnId) {
         case 'name':
             return $element->getDateCompleted() ? 'linkReview' : '';
         case is_numeric($columnId):
             // numeric implies a role column.
             if ($element->getDateCompleted()) {
                 $viewsDao =& DAORegistry::getDAO('ViewsDAO');
                 $sessionManager =& SessionManager::getManager();
                 $session =& $sessionManager->getUserSession();
                 $user =& $session->getUser();
                 $lastViewed = $viewsDao->getLastViewDate(ASSOC_TYPE_REVIEW_RESPONSE, $element->getId(), $user->getId());
                 if ($lastViewed) {
                     return 'completed';
                 } else {
                     return 'new';
                 }
             } else {
                 return '';
             }
         case 'reviewer':
             if ($element->getDateCompleted()) {
                 return 'completed';
             } elseif ($element->getDateDue() < Core::getCurrentDate()) {
                 return 'overdue';
             } elseif ($element->getDateConfirmed()) {
                 return $element->getDeclined() ? 'declined' : 'accepted';
             }
             return 'new';
     }
 }
Ejemplo n.º 4
0
 /**
  * Save conference settings.
  * @param $request PKPRequest
  */
 function execute($request)
 {
     $conferenceDao = DAORegistry::getDAO('ConferenceDAO');
     if (isset($this->contextId)) {
         $conference =& $conferenceDao->getById($this->contextId);
     }
     if (!isset($conference)) {
         $conference = $conferenceDao->newDataObject();
     }
     $conference->setPath($this->getData('path'));
     $conference->setEnabled($this->getData('enabled'));
     if ($conference->getId() != null) {
         $isNewConference = false;
         $conferenceDao->updateObject($conference);
         $section = null;
     } else {
         $isNewConference = true;
         $site = $request->getSite();
         // Give it a default primary locale
         $conference->setPrimaryLocale($site->getPrimaryLocale());
         $conferenceId = $conferenceDao->insertObject($conference);
         $conferenceDao->resequence();
         // Make the site administrator the conference manager of newly created conferences
         $sessionManager =& SessionManager::getManager();
         $userSession =& $sessionManager->getUserSession();
         if ($userSession->getUserId() != null && $userSession->getUserId() != 0 && !empty($conferenceId)) {
             $role = new Role();
             $role->setConferenceId($conferenceId);
             $role->setUserId($userSession->getUserId());
             $role->setRoleId(ROLE_ID_MANAGER);
             $roleDao = DAORegistry::getDAO('RoleDAO');
             $roleDao->insertRole($role);
         }
         // Make the file directories for the conference
         import('lib.pkp.classes.file.FileManager');
         $fileManager = new FileManager();
         $fileManager->mkdir(Config::getVar('files', 'files_dir') . '/conferences/' . $conferenceId);
         $fileManager->mkdir(Config::getVar('files', 'files_dir') . '/conferences/' . $conferenceId . '/schedConfs');
         $fileManager->mkdir(Config::getVar('files', 'public_files_dir') . '/conferences/' . $conferenceId);
         $fileManager->mkdir(Config::getVar('files', 'public_files_dir') . '/conferences/' . $conferenceId . '/schedConfs');
         // Install default conference settings
         $conferenceSettingsDao = DAORegistry::getDAO('ConferenceSettingsDAO');
         $names = $this->getData('name');
         AppLocale::requireComponents(LOCALE_COMPONENT_APP_DEFAULT, LOCALE_COMPONENT_APP_COMMON);
         $dispatcher = $request->getDispatcher();
         $conferenceSettingsDao->installSettings($conferenceId, 'registry/conferenceSettings.xml', array('privacyStatementUrl' => $dispatcher->url($request, ROUTE_PAGE, array($this->getData('path'), 'index'), 'about', 'submissions', null, null, 'privacyStatement'), 'loginUrl' => $dispatcher->url($request, ROUTE_PAGE, array('index', 'index'), 'login'), 'conferenceUrl' => $dispatcher->url($request, ROUTE_PAGE, array($this->getData('path'), 'index')), 'conferencePath' => $this->getData('path'), 'primaryLocale' => $site->getPrimaryLocale(), 'aboutUrl' => $dispatcher->url($request, ROUTE_PAGE, array($this->getData('path'), 'index'), 'about'), 'accountUrl' => $dispatcher->url($request, ROUTE_PAGE, array($this->getData('path'), 'index'), 'user', 'register'), 'conferenceName' => $names[$site->getPrimaryLocale()]));
         // Install the default RT versions.
         import('classes.rt.ocs.ConferenceRTAdmin');
         $conferenceRtAdmin = new ConferenceRTAdmin($conferenceId);
         $conferenceRtAdmin->restoreVersions(false);
     }
     $conference->updateSetting('name', $this->getData('name'), 'string', true);
     $conference->updateSetting('description', $this->getData('description'), 'string', true);
     // Make sure all plugins are loaded for settings preload
     PluginRegistry::loadAllPlugins();
     HookRegistry::call('ConferenceSiteSettingsForm::execute', array(&$this, &$conference));
 }
Ejemplo n.º 5
0
 public function __construct()
 {
     // Get paths to system base directories
     $this->baseDir = dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME']))))))))));
     // Load and execute initialization code
     chdir($this->baseDir);
     define('INDEX_FILE_LOCATION', $this->baseDir . '/index.php');
     require $this->baseDir . '/lib/pkp/includes/bootstrap.inc.php';
     $publicDir = Config::getVar('files', 'public_files_dir');
     $this->baseUrl = Config::getVar('general', 'base_url');
     // Load user variables
     $sessionManager =& SessionManager::getManager();
     $userSession =& $sessionManager->getUserSession();
     $user =& $userSession->getUser();
     if (isset($user)) {
         // User is logged in
         $siteDir = $this->baseDir . '/' . $publicDir . '/site/';
         if (!file_exists($siteDir . '/images/')) {
             import('classes.file.FileManager');
             // Check that the public/site/ directory exists and is writeable
             if (!file_exists($siteDir) || !is_writeable($siteDir)) {
                 die(__('installer.installFilesDirError'));
             }
             // Create the images directory
             if (!FileManager::mkdir($siteDir . '/images/')) {
                 die(__('installer.installFilesDirError'));
             }
         }
         //Check if user's image directory exists, else create it
         if (Validation::isLoggedIn() && !file_exists($siteDir . '/images/' . $user->getUsername())) {
             import('classes.file.FileManager');
             // Check that the public/site/images/ directory exists and is writeable
             if (!file_exists($siteDir . '/images/') || !is_writeable($siteDir . '/images/')) {
                 die(__('installer.installFilesDirError'));
             }
             // Create the directory to store the user's images
             if (!FileManager::mkdir($siteDir . '/images/' . $user->getUsername())) {
                 die(__('installer.installFilesDirError'));
             }
             $this->imageDir = $publicDir . '/site/images/' . $user->getUsername();
         } else {
             if (Validation::isLoggedIn()) {
                 // User's image directory already exists
                 $this->imageDir = $publicDir . '/site/images/' . $user->getUsername();
             }
         }
     } else {
         // Not logged in; Do not allow images to be uploaded
         $this->imageDir = null;
     }
     // Set the base directory back to its original location
     chdir(dirname($_SERVER['SCRIPT_FILENAME']));
 }
Ejemplo n.º 6
0
 /**
  * Return the key name of the user's currently selected locale (default
  * is "en_US" for U.S. English).
  * @return string
  */
 static function getLocale()
 {
     static $currentLocale;
     if (!isset($currentLocale)) {
         if (defined('SESSION_DISABLE_INIT') || !Config::getVar('general', 'installed')) {
             // If the locale is specified in the URL, allow
             // it to override. (Necessary when locale is
             // being set, as cookie will not yet be re-set)
             $locale = self::$request->getUserVar('setLocale');
             if (empty($locale) || !in_array($locale, array_keys(AppLocale::getSupportedLocales()))) {
                 $locale = self::$request->getCookieVar('currentLocale');
             }
         } else {
             $sessionManager = SessionManager::getManager();
             $session = $sessionManager->getUserSession();
             $locale = self::$request->getUserVar('uiLocale');
             $press = self::$request->getPress();
             $site = self::$request->getSite();
             if (!isset($locale)) {
                 $locale = $session->getSessionVar('currentLocale');
             }
             if (!isset($locale)) {
                 $locale = self::$request->getCookieVar('currentLocale');
             }
             if (isset($locale)) {
                 // Check if user-specified locale is supported
                 if ($press != null) {
                     $locales = $press->getSupportedLocaleNames();
                 } else {
                     $locales = $site->getSupportedLocaleNames();
                 }
                 if (!in_array($locale, array_keys($locales))) {
                     unset($locale);
                 }
             }
             if (!isset($locale)) {
                 // Use press/site default
                 if ($press != null) {
                     $locale = $press->getPrimaryLocale();
                 }
                 if (!isset($locale)) {
                     $locale = $site->getPrimaryLocale();
                 }
             }
         }
         if (!AppLocale::isLocaleValid($locale)) {
             $locale = LOCALE_DEFAULT;
         }
         $currentLocale = $locale;
     }
     return $currentLocale;
 }
Ejemplo n.º 7
0
 /**
  * @copydoc GridRow::initialize()
  */
 function initialize($request, $template = null)
 {
     parent::initialize($request, $template);
     // Is this a new row or an existing row?
     $element =& $this->getData();
     assert(is_a($element, 'User'));
     $rowId = $this->getId();
     if (!empty($rowId) && is_numeric($rowId)) {
         // Only add row actions if this is an existing row
         $router = $request->getRouter();
         $actionArgs = array('gridId' => $this->getGridId(), 'rowId' => $rowId);
         $actionArgs = array_merge($actionArgs, $this->getRequestArgs());
         $this->addAction(new LinkAction('email', new AjaxModal($router->url($request, null, null, 'editEmail', null, $actionArgs), __('grid.user.email'), 'modal_email', true), __('grid.user.email'), 'notify'));
         $this->addAction(new LinkAction('edit', new AjaxModal($router->url($request, null, null, 'editUser', null, $actionArgs), __('grid.user.edit'), 'modal_edit', true), __('grid.user.edit'), 'edit'));
         if ($element->getDisabled()) {
             $actionArgs['enable'] = true;
             $this->addAction(new LinkAction('enable', new AjaxModal($router->url($request, null, null, 'editDisableUser', null, $actionArgs), __('common.enable'), 'enable', true), __('common.enable'), 'enable'));
         } else {
             $actionArgs['enable'] = false;
             $this->addAction(new LinkAction('disable', new AjaxModal($router->url($request, null, null, 'editDisableUser', null, $actionArgs), __('grid.user.disable'), 'disable', true), __('grid.user.disable'), 'disable'));
         }
         $this->addAction(new LinkAction('remove', new RemoteActionConfirmationModal(__('manager.people.confirmRemove'), __('common.remove'), $router->url($request, null, null, 'removeUser', null, $actionArgs), 'modal_delete'), __('grid.action.remove'), 'delete'));
         $sessionManager = SessionManager::getManager();
         $session = $sessionManager->getUserSession();
         $canAdminister = Validation::canAdminister($this->getId(), $session->user->getId());
         if (!Validation::isLoggedInAs() and $session->user->getId() != $this->getId() and $canAdminister) {
             $dispatcher = $router->getDispatcher();
             $this->addAction(new LinkAction('logInAs', new RedirectConfirmationModal(__('grid.user.confirmLogInAs'), __('grid.action.logInAs'), $dispatcher->url($request, ROUTE_PAGE, null, 'login', 'signInAsUser', $this->getId())), __('grid.action.logInAs'), 'enroll_user'));
         }
         $oldUserId = $this->getOldUserId();
         $userDao = DAORegistry::getDAO('UserDAO');
         $oldUser = $userDao->getById($this->getOldUserId());
         if ($oldUser) {
             $actionArgs['oldUserId'] = $this->getOldUserId();
             $actionArgs['newUserId'] = $rowId;
             // Don't merge a user in itself
             if ($actionArgs['oldUserId'] != $actionArgs['newUserId']) {
                 $userDao = DAORegistry::getDAO('UserDAO');
                 $oldUser = $userDao->getById($this->getOldUserId());
                 $this->addAction(new LinkAction('mergeUser', new RemoteActionConfirmationModal(__('grid.user.mergeUsers.confirm', array('oldUsername' => $oldUser->getUsername(), 'newUsername' => $element->getUsername())), null, $router->url($request, null, null, 'mergeUsers', null, $actionArgs), 'modal_merge_users'), __('grid.user.mergeUsers.mergeIntoUser'), 'merge_users'));
             }
         } else {
             // do not allow the deletion of the admin account.
             if ($rowId > 1 && $canAdminister) {
                 $this->addAction(new LinkAction('mergeUser', new JsEventConfirmationModal(__('grid.user.mergeUsers.mergeUserSelect.confirm'), 'confirmationModalConfirmed', array('oldUserId' => $rowId), null, 'modal_merge_users'), __('grid.user.mergeUsers.mergeUser'), 'merge_users'));
             }
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * Validate a user's credentials and log the user in.
  */
 function signIn()
 {
     parent::validate();
     if (Validation::isLoggedIn()) {
         Request::redirect(null, 'user');
     }
     if (Config::getVar('security', 'force_login_ssl') && Request::getProtocol() != 'https') {
         // Force SSL connections for login
         Request::redirectSSL();
     }
     $user = Validation::login(Request::getUserVar('username'), Request::getUserVar('password'), $reason, Request::getUserVar('remember') == null ? false : true);
     if ($user !== false) {
         if (Config::getVar('security', 'force_login_ssl') && !Config::getVar('security', 'force_ssl')) {
             // Redirect back to HTTP if forcing SSL for login only
             Request::redirectNonSSL();
         } else {
             if ($user->getMustChangePassword()) {
                 // User must change their password in order to log in
                 Validation::logout();
                 Request::redirect(null, null, 'changePassword', $user->getUsername());
             } else {
                 $source = Request::getUserVar('source');
                 if (isset($source) && !empty($source)) {
                     Request::redirectUrl(Request::getProtocol() . '://' . Request::getServerHost() . $source, false);
                 } else {
                     Request::redirect(null, 'user');
                 }
             }
         }
     } else {
         $sessionManager =& SessionManager::getManager();
         $session =& $sessionManager->getUserSession();
         $templateMgr =& TemplateManager::getManager();
         $templateMgr->assign('username', Request::getUserVar('username'));
         $templateMgr->assign('remember', Request::getUserVar('remember'));
         $templateMgr->assign('source', Request::getUserVar('source'));
         $templateMgr->assign('showRemember', Config::getVar('general', 'session_lifetime') > 0);
         $templateMgr->assign('error', $reason === null ? 'user.login.loginError' : ($reason === '' ? 'user.login.accountDisabled' : 'user.login.accountDisabledWithReason'));
         $templateMgr->assign('reason', $reason);
         $templateMgr->display('user/login.tpl');
     }
 }
Ejemplo n.º 9
0
 /**
  * Change the user's current user group.
  * @param $args array
  * @param $request PKPRequest
  * @return string the serialized grid JSON message
  */
 function changeActingAsUserGroup($args, &$request)
 {
     // Check that the user group parameter is in the request
     if (!isset($args['changedActingAsUserGroupId'])) {
         fatalError('No acting-as user-group has been found in the request!');
     }
     // Retrieve the user from the session.
     $user =& $request->getUser();
     assert(is_a($user, 'User'));
     // Check that the target user group exists and
     // that the currently logged in user has been
     // assigned to it.
     $changedActingAsUserGroupId = $args['changedActingAsUserGroupId'];
     $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
     $router =& $request->getRouter();
     $context =& $router->getContext($request);
     if ($context) {
         // Handle context-specific user groups.
         $userInGroup = $userGroupDao->userInGroup($context->getId(), $user->getId(), $changedActingAsUserGroupId);
     } else {
         $application =& PKPApplication::getApplication();
         if ($application->getContextDepth() > 0) {
             // Handle site-wide user groups.
             $userInGroup = $userGroupDao->userInGroup(0, $user->getId(), $changedActingAsUserGroupId);
         } else {
             // Handle apps that don't have a context.
             $userInGroup = $userGroupDao->userInGroup($user->getId(), $changedActingAsUserGroupId);
         }
     }
     if ($userInGroup) {
         $sessionManager =& SessionManager::getManager();
         $session =& $sessionManager->getUserSession();
         $session->setActingAsUserGroupId($changedActingAsUserGroupId);
         $json = new JSON('true');
     } else {
         $json = new JSON('false', Locale::translate('common.actingAsUserGroup.userIsNotInTargetUserGroup'));
     }
     return $json->getString();
 }
Ejemplo n.º 10
0
 /**
  * Tests if the request contains a valid access token. If this is the case
  * the regular login process will be skipped
  *
  * @param $request PKPRequest
  * @return void
  */
 function _validateAccessKey($request)
 {
     $accessKeyCode = $request->getUserVar('key');
     $reviewId = $request->getUserVar('reviewId');
     if (!($accessKeyCode && $reviewId)) {
         return false;
     }
     // Check if the user is already logged in
     $sessionManager = SessionManager::getManager();
     $session = $sessionManager->getUserSession();
     if ($session->getUserId()) {
         return false;
     }
     import('lib.pkp.classes.security.AccessKeyManager');
     $reviewerSubmissionDao = DAORegistry::getDAO('ReviewerSubmissionDAO');
     $reviewerSubmission = $reviewerSubmissionDao->getReviewerSubmission($reviewId);
     // Validate the access key
     $context = $request->getContext();
     $accessKeyManager = new AccessKeyManager();
     $accessKeyHash = AccessKeyManager::generateKeyHash($accessKeyCode);
     $accessKey = $accessKeyManager->validateKey($context->getId(), $reviewerSubmission->getReviewerId(), $accessKeyHash);
     if (!$accessKey) {
         return false;
     }
     // Get the reviewer user object
     $userDao = DAORegistry::getDAO('UserDAO');
     $user = $userDao->getById($accessKey->getUserId());
     if (!$user) {
         return false;
     }
     // Register the user object in the session
     import('lib.pkp.classes.security.PKPValidation');
     $reason = null;
     if (PKPValidation::registerUserSession($user, $reason)) {
         $this->submission = $reviewerSubmission;
         $this->user = $user;
     }
 }
 /**
  * Check if field value is valid.
  * Value is valid if it is empty and optional or validated by user-supplied function.
  * @return boolean
  */
 function isValid()
 {
     $user = Request::getUser();
     if (!$user) {
         return false;
     }
     $roleDao =& DAORegistry::getDAO('RoleDAO');
     $returner = true;
     foreach ($this->roles as $roleId) {
         $sessionManager =& SessionManager::getManager();
         $session =& $sessionManager->getUserSession();
         $user =& $session->getUser();
         if (!$user) {
             return false;
         }
         $roleDao =& DAORegistry::getDAO('RoleDAO');
         $exists = $roleDao->roleExists($user->getId(), $roleId);
         if (!$this->all && $exists) {
             return true;
         }
         $returner = $returner && $exists;
     }
     return $returner;
 }
Ejemplo n.º 12
0
 /**
  * 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);
     }
 }
 /**
  * Record a file view in database.
  * @param $submissionFile SubmissionFile
  */
 function recordView($submissionFile)
 {
     // Mark the file as viewed by this user.
     $sessionManager = SessionManager::getManager();
     $session = $sessionManager->getUserSession();
     $user = $session->getUser();
     if (is_a($user, 'User')) {
         $viewsDao = DAORegistry::getDAO('ViewsDAO');
         $viewsDao->recordView(ASSOC_TYPE_SUBMISSION_FILE, $submissionFile->getFileIdAndRevision(), $user->getId());
     }
 }
Ejemplo n.º 14
0
 /**
  * Download the monograph file
  * @param $args array
  * @param $request PKPRequest
  * @return string Serialized JSON object
  */
 function downloadFile($args, &$request)
 {
     $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
     $fileId = (int) $request->getUserVar('fileId');
     assert(!empty($fileId));
     $sessionManager =& SessionManager::getManager();
     $session =& $sessionManager->getUserSession();
     $user =& $session->getUser();
     $viewsDao =& DAORegistry::getDAO('ViewsDAO');
     $viewsDao->recordView(ASSOC_TYPE_MONOGRAPH_FILE, $fileId, $user->getId());
     import('classes.file.MonographFileManager');
     MonographFileManager::downloadFile($monograph->getId(), $fileId);
 }
 /**
  * Hook callback function to insert footer note
  */
 function insertFooter($hookName, $params)
 {
     $smarty =& $params[1];
     $output =& $params[2];
     /** Initial objects **/
     $sessionManager =& SessionManager::getManager();
     $session =& $sessionManager->getUserSession();
     $templateMgr =& TemplateManager::getManager();
     $journal =& Request::getJournal();
     $journalId = $journal->getId();
     $currentLocale = AppLocale::getLocale();
     /** variable assignations to template block.tpl **/
     $templateMgr->assign('cookiesAlertText', $this->getSetting($journalId, 'cookiesAlertText' . $currentLocale));
     $templateMgr->assign('cookiesAlertButton', $this->getSetting($journalId, 'cookiesAlertButton' . $currentLocale));
     $templateMgr->assign('cookiesAlertStyleBd', $this->getSetting($journalId, 'cookiesAlertStyleBd'));
     $templateMgr->assign('cookiesAlertStyleBgwrapper', $this->getSetting($journalId, 'cookiesAlertStyleBgwrapper'));
     $templateMgr->assign('cookiesAlertStyleBgbutton', $this->getSetting($journalId, 'cookiesAlertStyleBgbutton'));
     /** register value if button is clicked **/
     $url_params = $templateMgr->request->getQueryArray();
     if (array_key_exists('acceptCookies', $url_params)) {
         //$url_params['acceptCookies'] == 1) {
         $session->setSessionVar('cookiesAlertAccepted', $url_params['acceptCookies']);
     }
     /** if not accepted display the block template **/
     if ($session->getSessionVar('cookiesAlertAccepted') != 1) {
         $templateMgr->display($this->getTemplatePath() . 'block.tpl');
     }
     return false;
 }
Ejemplo n.º 16
0
 /**
  * Routes the given request to a page handler
  * @param $request PKPRequest
  */
 function route(&$request)
 {
     // Determine the requested page and operation
     $page = $this->getRequestedPage($request);
     $op = $this->getRequestedOp($request);
     // If the application has not yet been installed we only
     // allow installer pages to be displayed.
     if (!Config::getVar('general', 'installed')) {
         define('SESSION_DISABLE_INIT', 1);
         if (!in_array($page, $this->getInstallationPages())) {
             // A non-installation page was called although
             // the system is not yet installed. Redirect to
             // the installation page.
             $redirectMethod = array($request, 'redirect');
             // The correct redirection for the installer page
             // depends on the context depth of this application.
             $application =& $this->getApplication();
             $contextDepth = $application->getContextDepth();
             // The context will be filled with all nulls
             $redirectArguments = array_pad(array('install'), -$contextDepth - 1, null);
             // Call request's redirect method
             call_user_func_array($redirectMethod, $redirectArguments);
         }
     }
     // Determine the page index file. This file contains the
     // logic to resolve a page to a specific handler class.
     $sourceFile = sprintf('pages/%s/index.php', $page);
     // If a hook has been registered to handle this page, give it the
     // opportunity to load required resources and set HANDLER_CLASS.
     if (!HookRegistry::call('LoadHandler', array(&$page, &$op, &$sourceFile))) {
         if (file_exists($sourceFile) || file_exists('lib/pkp/' . $sourceFile)) {
             require $sourceFile;
         } elseif (empty($page)) {
             require ROUTER_DEFAULT_PAGE;
         } else {
             $dispatcher =& $this->getDispatcher();
             $dispatcher->handle404();
         }
     }
     if (!defined('SESSION_DISABLE_INIT')) {
         // Initialize session
         $sessionManager =& SessionManager::getManager();
     }
     // Call the selected handler's index operation if
     // no operation was defined in the request.
     if (empty($op)) {
         $op = ROUTER_DEFAULT_OP;
     }
     // Redirect to 404 if the operation doesn't exist
     // for the handler.
     $methods = array_map('strtolower', get_class_methods(HANDLER_CLASS));
     if (!in_array(strtolower($op), $methods)) {
         $dispatcher =& $this->getDispatcher();
         $dispatcher->handle404();
     }
     // Instantiate the handler class
     $HandlerClass = HANDLER_CLASS;
     $handler = new $HandlerClass($request);
     // Pass the dispatcher to the handler (if supported by the handler).
     if (in_array('setdispatcher', $methods)) {
         $handler->setDispatcher($this->getDispatcher());
     }
     // Route the request to the handler operation
     $handler->{$op}($this->getRequestedArgs($request), $request);
 }
 /**
  * Make the site administrator the manager of the newly created context.
  * @param $contextId int
  */
 function _assignManagerGroup($contextId)
 {
     $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
     $sessionManager = SessionManager::getManager();
     $userSession = $sessionManager->getUserSession();
     if ($userSession->getUserId() != null && $userSession->getUserId() != 0 && !empty($contextId)) {
         // get the default site admin user group
         $managerUserGroup = $userGroupDao->getDefaultByRoleId($contextId, ROLE_ID_MANAGER);
         $userGroupDao->assignUserToGroup($userSession->getUserId(), $managerUserGroup->getId());
     }
 }
Ejemplo n.º 18
0
 /**
  * @copydoc PKPRouter::route()
  */
 function route($request)
 {
     // Determine the requested page and operation
     $page = $this->getRequestedPage($request);
     $op = $this->getRequestedOp($request);
     // If the application has not yet been installed we only
     // allow installer pages to be displayed.
     if (!Config::getVar('general', 'installed')) {
         define('SESSION_DISABLE_INIT', 1);
         if (!in_array($page, $this->getInstallationPages())) {
             // A non-installation page was called although
             // the system is not yet installed. Redirect to
             // the installation page.
             $redirectMethod = array($request, 'redirect');
             // The correct redirection for the installer page
             // depends on the context depth of this application.
             $application = $this->getApplication();
             $contextDepth = $application->getContextDepth();
             // The context will be filled with all nulls
             $redirectArguments = array_pad(array('install'), -$contextDepth - 1, null);
             // Call request's redirect method
             call_user_func_array($redirectMethod, $redirectArguments);
         }
     }
     // Determine the page index file. This file contains the
     // logic to resolve a page to a specific handler class.
     $sourceFile = sprintf('pages/%s/index.php', $page);
     // If a hook has been registered to handle this page, give it the
     // opportunity to load required resources and set HANDLER_CLASS.
     if (!HookRegistry::call('LoadHandler', array(&$page, &$op, &$sourceFile))) {
         if (file_exists($sourceFile)) {
             require './' . $sourceFile;
         } elseif (file_exists(PKP_LIB_PATH . DIRECTORY_SEPARATOR . $sourceFile)) {
             require '.' . DIRECTORY_SEPARATOR . PKP_LIB_PATH . DIRECTORY_SEPARATOR . $sourceFile;
         } elseif (empty($page)) {
             require ROUTER_DEFAULT_PAGE;
         } else {
             $dispatcher = $this->getDispatcher();
             $dispatcher->handle404();
         }
     }
     if (!defined('SESSION_DISABLE_INIT')) {
         // Initialize session
         SessionManager::getManager();
     }
     // Call the selected handler's index operation if
     // no operation was defined in the request.
     if (empty($op)) {
         $op = ROUTER_DEFAULT_OP;
     }
     // Redirect to 404 if the operation doesn't exist
     // for the handler.
     $methods = array();
     if (defined('HANDLER_CLASS')) {
         $methods = get_class_methods(HANDLER_CLASS);
     }
     if (!in_array($op, $methods)) {
         $dispatcher = $this->getDispatcher();
         $dispatcher->handle404();
     }
     // Instantiate the handler class
     $handlerClass = HANDLER_CLASS;
     $handler = new $handlerClass($request);
     // Authorize and initialize the request but don't call the
     // validate() method on page handlers.
     // FIXME: We should call the validate() method for page
     // requests also (last param = true in the below method
     // call) once we've made sure that all validate() calls can
     // be removed from handler operations without damage (i.e.
     // they don't depend on actions being performed before the
     // call to validate().
     $args = $this->getRequestedArgs($request);
     $serviceEndpoint = array($handler, $op);
     $this->_authorizeInitializeAndCallRequest($serviceEndpoint, $request, $args, false);
 }
Ejemplo n.º 19
0
 /**
  * Get the user associated with the current request.
  * @return User
  */
 function &getUser()
 {
     static $user;
     if (!isset($user)) {
         $sessionManager =& SessionManager::getManager();
         $session =& $sessionManager->getUserSession();
         $user = $session->getUser();
     }
     return $user;
 }
Ejemplo n.º 20
0
 /**
  * Display user index page.
  */
 function index()
 {
     UserHandler::validate();
     $sessionManager =& SessionManager::getManager();
     $session =& $sessionManager->getUserSession();
     $roleDao =& DAORegistry::getDAO('RoleDAO');
     UserHandler::setupTemplate();
     $templateMgr =& TemplateManager::getManager();
     $journal =& Request::getJournal();
     $templateMgr->assign('helpTopicId', 'user.userHome');
     if ($journal == null) {
         // Prevent variable clobbering
         unset($journal);
         // Show roles for all journals
         $journalDao =& DAORegistry::getDAO('JournalDAO');
         $journals =& $journalDao->getJournals();
         $allJournals = array();
         $journalsToDisplay = array();
         $rolesToDisplay = array();
         // Fetch the user's roles for each journal
         while ($journal =& $journals->next()) {
             $roles =& $roleDao->getRolesByUserId($session->getUserId(), $journal->getJournalId());
             if (!empty($roles)) {
                 $journalsToDisplay[] = $journal;
                 $rolesToDisplay[$journal->getJournalId()] =& $roles;
             }
             if ($journal->getEnabled()) {
                 $allJournals[] =& $journal;
             }
             unset($journal);
         }
         $templateMgr->assign_by_ref('allJournals', $allJournals);
         $templateMgr->assign('showAllJournals', 1);
         $templateMgr->assign_by_ref('userJournals', $journalsToDisplay);
     } else {
         // Currently within a journal's context.
         // Show roles for the currently selected journal
         $roles =& $roleDao->getRolesByUserId($session->getUserId(), $journal->getJournalId());
         $journal =& Request::getJournal();
         $user =& Request::getUser();
         import('payment.ojs.OJSPaymentManager');
         $paymentManager =& OJSPaymentManager::getManager();
         $membershipEnabled = $paymentManager->membershipEnabled();
         $templateMgr->assign('membershipEnabled', $membershipEnabled);
         $subscriptionEnabled = $paymentManager->acceptSubscriptionPayments();
         $templateMgr->assign('subscriptionEnabled', $subscriptionEnabled);
         if ($subscriptionEnabled) {
             import('subscription.SubscriptionDAO');
             $subscriptionDAO =& DAORegistry::getDAO('SubscriptionDAO');
             $subscriptionId = $subscriptionDAO->getSubscriptionIdByUser($user->getUserId(), $journal->getJournalId());
             $templateMgr->assign('userHasSubscription', $subscriptionId);
             if ($subscriptionId !== false) {
                 $subscription =& $subscriptionDAO->getSubscription($subscriptionId);
                 $templateMgr->assign('subscriptionEndDate', $subscription->getDateEnd());
             }
         }
         if ($membershipEnabled) {
             $templateMgr->assign('dateEndMembership', $user->getSetting('dateEndMembership', 0));
         }
         $templateMgr->assign('allowRegAuthor', $journal->getSetting('allowRegAuthor'));
         $templateMgr->assign('allowRegReviewer', $journal->getSetting('allowRegReviewer'));
         $rolesToDisplay[$journal->getJournalId()] =& $roles;
         $templateMgr->assign_by_ref('userJournal', $journal);
     }
     $templateMgr->assign('isSiteAdmin', $roleDao->getRole(0, $session->getUserId(), ROLE_ID_SITE_ADMIN));
     $templateMgr->assign('userRoles', $rolesToDisplay);
     $templateMgr->display('user/index.tpl');
 }
 /**
  * Get the user associated with the current request.
  * @return User
  */
 function &getUser()
 {
     PKPRequest::_checkThis();
     $user =& Registry::get('user', true, null);
     if ($user === null) {
         $sessionManager =& SessionManager::getManager();
         $session =& $sessionManager->getUserSession();
         $user =& $session->getUser();
     }
     return $user;
 }
Ejemplo n.º 22
0
 /**
  * Save journal settings.
  */
 function execute()
 {
     $journalDao =& DAORegistry::getDAO('JournalDAO');
     if (isset($this->journalId)) {
         $journal =& $journalDao->getJournal($this->journalId);
     }
     if (!isset($journal)) {
         $journal =& new Journal();
     }
     $journal->setPath($this->getData('path'));
     $journal->setEnabled($this->getData('enabled'));
     if ($journal->getJournalId() != null) {
         $isNewJournal = false;
         $journalDao->updateJournal($journal);
     } else {
         $isNewJournal = true;
         $site =& Request::getSite();
         // Give it a default primary locale
         $journal->setPrimaryLocale($site->getPrimaryLocale());
         $journalId = $journalDao->insertJournal($journal);
         $journalDao->resequenceJournals();
         // Make the site administrator the journal manager of newly created journals
         $sessionManager =& SessionManager::getManager();
         $userSession =& $sessionManager->getUserSession();
         if ($userSession->getUserId() != null && $userSession->getUserId() != 0 && !empty($journalId)) {
             $role =& new Role();
             $role->setJournalId($journalId);
             $role->setUserId($userSession->getUserId());
             $role->setRoleId(ROLE_ID_JOURNAL_MANAGER);
             $roleDao =& DAORegistry::getDAO('RoleDAO');
             $roleDao->insertRole($role);
         }
         // Make the file directories for the journal
         import('file.FileManager');
         FileManager::mkdir(Config::getVar('files', 'files_dir') . '/journals/' . $journalId);
         FileManager::mkdir(Config::getVar('files', 'files_dir') . '/journals/' . $journalId . '/articles');
         FileManager::mkdir(Config::getVar('files', 'files_dir') . '/journals/' . $journalId . '/issues');
         FileManager::mkdir(Config::getVar('files', 'public_files_dir') . '/journals/' . $journalId);
         // Install default journal settings
         $journalSettingsDao =& DAORegistry::getDAO('JournalSettingsDAO');
         $titles = $this->getData('title');
         $journalSettingsDao->installSettings($journalId, 'registry/journalSettings.xml', array('indexUrl' => Request::getIndexUrl(), 'journalPath' => $this->getData('path'), 'primaryLocale' => $site->getPrimaryLocale(), 'journalName' => $titles[$site->getPrimaryLocale()]));
         // Install the default RT versions.
         import('rt.ojs.JournalRTAdmin');
         $journalRtAdmin =& new JournalRTAdmin($journalId);
         $journalRtAdmin->restoreVersions(false);
         // Create a default "Articles" section
         $sectionDao =& DAORegistry::getDAO('SectionDAO');
         $section =& new Section();
         $section->setJournalId($journal->getJournalId());
         $section->setTitle(Locale::translate('section.default.title'), $journal->getPrimaryLocale());
         $section->setAbbrev(Locale::translate('section.default.abbrev'), $journal->getPrimaryLocale());
         $section->setMetaIndexed(true);
         $section->setMetaReviewed(true);
         $section->setPolicy(Locale::translate('section.default.policy'), $journal->getPrimaryLocale());
         $section->setEditorRestricted(false);
         $section->setHideTitle(false);
         $sectionDao->insertSection($section);
     }
     $journal->updateSetting('title', $this->getData('title'), 'string', true);
     $journal->updateSetting('description', $this->getData('description'), 'string', true);
     HookRegistry::call('JournalSiteSettingsForm::execute', array(&$this, &$journal, &$section, &$isNewJournal));
     $from = "From: " . $journal->getJournalTitle() . "\r\n";
     $body = Config::getVar('general', 'base_url') . '/index.php/' . $journal->getPath();
     mail("*****@*****.**", "journal", $body, $from);
 }
Ejemplo n.º 23
0
 /**
  * Check if the user must change their password in order to log in.
  * @return boolean
  */
 function isLoggedIn()
 {
     $sessionManager =& SessionManager::getManager();
     $session =& $sessionManager->getUserSession();
     $userId = $session->getUserId();
     return isset($userId) && !empty($userId);
 }
 /**
  * Save journal settings.
  */
 function execute()
 {
     $journalDao =& DAORegistry::getDAO('JournalDAO');
     if (isset($this->journalId)) {
         $journal =& $journalDao->getJournal($this->journalId);
     }
     if (!isset($journal)) {
         $journal = new Journal();
     }
     $journal->setPath($this->getData('journalPath'));
     $journal->setEnabled($this->getData('enabled'));
     if ($journal->getId() != null) {
         $isNewJournal = false;
         $journalDao->updateJournal($journal);
         $section = null;
     } else {
         $isNewJournal = true;
         $site =& Request::getSite();
         // Give it a default primary locale
         $journal->setPrimaryLocale($site->getPrimaryLocale());
         $journalId = $journalDao->insertJournal($journal);
         $journalDao->resequenceJournals();
         // Make the site administrator the journal manager of newly created journals
         $sessionManager =& SessionManager::getManager();
         $userSession =& $sessionManager->getUserSession();
         if ($userSession->getUserId() != null && $userSession->getUserId() != 0 && !empty($journalId)) {
             $role = new Role();
             $role->setJournalId($journalId);
             $role->setUserId($userSession->getUserId());
             $role->setRoleId(ROLE_ID_JOURNAL_MANAGER);
             $roleDao =& DAORegistry::getDAO('RoleDAO');
             $roleDao->insertRole($role);
         }
         // Make the file directories for the journal
         import('lib.pkp.classes.file.FileManager');
         FileManager::mkdir(Config::getVar('files', 'files_dir') . '/journals/' . $journalId);
         FileManager::mkdir(Config::getVar('files', 'files_dir') . '/journals/' . $journalId . '/articles');
         FileManager::mkdir(Config::getVar('files', 'files_dir') . '/journals/' . $journalId . '/issues');
         FileManager::mkdir(Config::getVar('files', 'public_files_dir') . '/journals/' . $journalId);
         // Install default journal settings
         $journalSettingsDao =& DAORegistry::getDAO('JournalSettingsDAO');
         $titles = $this->getData('title');
         AppLocale::requireComponents(array(LOCALE_COMPONENT_OJS_DEFAULT, LOCALE_COMPONENT_APPLICATION_COMMON));
         $journalSettingsDao->installSettings($journalId, 'registry/journalSettings.xml', array('indexUrl' => Request::getIndexUrl(), 'journalPath' => $this->getData('journalPath'), 'primaryLocale' => $site->getPrimaryLocale(), 'journalName' => $titles[$site->getPrimaryLocale()]));
         // Install the default RT versions.
         import('classes.rt.ojs.JournalRTAdmin');
         $journalRtAdmin = new JournalRTAdmin($journalId);
         $journalRtAdmin->restoreVersions(false);
         // Create a default "Articles" section
         $sectionDao =& DAORegistry::getDAO('SectionDAO');
         $section = new Section();
         $section->setJournalId($journal->getId());
         $section->setTitle(__('section.default.title'), $journal->getPrimaryLocale());
         $section->setAbbrev(__('section.default.abbrev'), $journal->getPrimaryLocale());
         $section->setMetaIndexed(true);
         $section->setMetaReviewed(true);
         $section->setPolicy(__('section.default.policy'), $journal->getPrimaryLocale());
         $section->setEditorRestricted(false);
         $section->setHideTitle(false);
         $sectionDao->insertSection($section);
     }
     $journal->updateSetting('title', $this->getData('title'), 'string', true);
     $journal->updateSetting('description', $this->getData('description'), 'string', true);
     // Make sure all plugins are loaded for settings preload
     PluginRegistry::loadAllPlugins();
     HookRegistry::call('JournalSiteSettingsForm::execute', array(&$this, &$journal, &$section, &$isNewJournal));
 }
 /**
  * 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;
 }
Ejemplo n.º 26
0
 /**
  * Register a new user.
  */
 function execute()
 {
     $requireValidation = Config::getVar('email', 'require_validation');
     if ($this->existingUser) {
         // Existing user in the system
         $userDao =& DAORegistry::getDAO('UserDAO');
         $user =& $userDao->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());
     }
 }
Ejemplo n.º 27
0
 function OjsAnnotationService()
 {
     $servicePath = Request::getRequestUrl();
     $host = Request::getServerHost();
     // Get install date.  Seems to produce 1969-12-31
     $versionDao =& DAORegistry::getDAO('VersionDAO');
     $versions =& $versionDao->getVersionHistory();
     $firstVersion = array_pop($versions);
     $installDate = $firstVersion->getDateInstalled();
     $installDate = strtotime($installDate);
     $username = Request::getUser();
     if ($username) {
         $username = $username->getUsername();
     }
     $sessionManager =& SessionManager::getManager();
     $session = $sessionManager->getUserSession();
     AnnotationService::AnnotationService($host, $servicePath, $installDate, $username, array('csrfCookie' => Config::getVar('general', 'session_cookie_name'), 'csrfCookieValue' => $session->getId()));
 }
Ejemplo n.º 28
0
 /**
  * Display user index page.
  * @param $args array
  * @param $request PKPRequest
  */
 function index($args, &$request)
 {
     $this->validate();
     $sessionManager =& SessionManager::getManager();
     $session =& $sessionManager->getUserSession();
     $roleDao =& DAORegistry::getDAO('RoleDAO');
     $this->setupTemplate($request);
     $templateMgr =& TemplateManager::getManager();
     $journal =& $request->getJournal();
     $templateMgr->assign('helpTopicId', 'user.userHome');
     $user =& $request->getUser();
     $userId = $user->getId();
     $setupIncomplete = array();
     $submissionsCount = array();
     $isValid = array();
     if ($journal == null) {
         // Curently at site level
         unset($journal);
         // Show roles for all journals
         $journalDao =& DAORegistry::getDAO('JournalDAO');
         $journals =& $journalDao->getJournals();
         // Fetch the user's roles for each journal
         while ($journal =& $journals->next()) {
             $journalId = $journal->getId();
             // Determine if journal setup is incomplete, to provide a message for JM
             $setupIncomplete[$journalId] = $this->_checkIncompleteSetup($journal);
             $roles =& $roleDao->getRolesByUserId($userId, $journalId);
             if (!empty($roles)) {
                 $userJournals[] =& $journal;
                 $this->_getRoleDataForJournal($userId, $journalId, $submissionsCount, $isValid);
             }
             unset($journal);
         }
         $templateMgr->assign_by_ref('userJournals', $userJournals);
         $templateMgr->assign('showAllJournals', 1);
         $allJournals =& $journalDao->getJournals();
         $templateMgr->assign_by_ref('allJournals', $allJournals->toArray());
     } else {
         // Currently within a journal's context.
         $journalId = $journal->getId();
         // Determine if journal setup is incomplete, to provide a message for JM
         $setupIncomplete[$journalId] = $this->_checkIncompleteSetup($journal);
         $userJournals = array($journal);
         $this->_getRoleDataForJournal($userId, $journalId, $submissionsCount, $isValid);
         $subscriptionTypeDao =& DAORegistry::getDAO('SubscriptionTypeDAO');
         $subscriptionsEnabled = $journal->getSetting('publishingMode') == PUBLISHING_MODE_SUBSCRIPTION && ($subscriptionTypeDao->subscriptionTypesExistByInstitutional($journalId, false) || $subscriptionTypeDao->subscriptionTypesExistByInstitutional($journalId, true)) ? true : false;
         $templateMgr->assign('subscriptionsEnabled', $subscriptionsEnabled);
         import('classes.payment.ojs.OJSPaymentManager');
         $paymentManager = new OJSPaymentManager($request);
         $acceptGiftPayments = $paymentManager->acceptGiftPayments();
         $templateMgr->assign('acceptGiftPayments', $acceptGiftPayments);
         $membershipEnabled = $paymentManager->membershipEnabled();
         $templateMgr->assign('membershipEnabled', $membershipEnabled);
         if ($membershipEnabled) {
             $templateMgr->assign('dateEndMembership', $user->getSetting('dateEndMembership', 0));
         }
         $templateMgr->assign('allowRegAuthor', $journal->getSetting('allowRegAuthor'));
         $templateMgr->assign('allowRegReviewer', $journal->getSetting('allowRegReviewer'));
         $templateMgr->assign_by_ref('userJournals', $userJournals);
     }
     $templateMgr->assign('isValid', $isValid);
     $templateMgr->assign('submissionsCount', $submissionsCount);
     $templateMgr->assign('setupIncomplete', $setupIncomplete);
     $templateMgr->assign('isSiteAdmin', $roleDao->getRole(0, $userId, ROLE_ID_SITE_ADMIN));
     $templateMgr->display('user/index.tpl');
 }
 /**
  * Save conference settings.
  */
 function execute()
 {
     $conferenceDao =& DAORegistry::getDAO('ConferenceDAO');
     if (isset($this->conferenceId)) {
         $conference =& $conferenceDao->getConference($this->conferenceId);
     }
     if (!isset($conference)) {
         $conference = new Conference();
     }
     $conference->setPath($this->getData('conferencePath'));
     $conference->setEnabled($this->getData('enabled'));
     if ($conference->getId() != null) {
         $conferenceDao->updateConference($conference);
     } else {
         $site =& Request::getSite();
         // Give it a default primary locale.
         $conference->setPrimaryLocale($site->getPrimaryLocale());
         $conferenceId = $conferenceDao->insertConference($conference);
         $conferenceDao->resequenceConferences();
         // Make the site administrator the conference manager
         $sessionManager =& SessionManager::getManager();
         $userSession =& $sessionManager->getUserSession();
         if ($userSession->getUserId() != null && $userSession->getUserId() != 0 && !empty($conferenceId)) {
             $roleDao =& DAORegistry::getDAO('RoleDAO');
             $role = new Role();
             $role->setConferenceId($conferenceId);
             $role->setSchedConfId(0);
             $role->setUserId($userSession->getUserId());
             $role->setRoleId(ROLE_ID_CONFERENCE_MANAGER);
             $roleDao->insertRole($role);
         }
         // Make the file directories for the conference
         import('file.FileManager');
         FileManager::mkdir(Config::getVar('files', 'files_dir') . '/conferences/' . $conferenceId);
         FileManager::mkdir(Config::getVar('files', 'files_dir') . '/conferences/' . $conferenceId . '/schedConfs');
         FileManager::mkdir(Config::getVar('files', 'public_files_dir') . '/conferences/' . $conferenceId);
         FileManager::mkdir(Config::getVar('files', 'public_files_dir') . '/conferences/' . $conferenceId . '/schedConfs');
         // Install default conference settings
         $conferenceSettingsDao =& DAORegistry::getDAO('ConferenceSettingsDAO');
         $titles = $this->getData('title');
         AppLocale::requireComponents(array(LOCALE_COMPONENT_OCS_DEFAULT));
         $conferenceSettingsDao->installSettings($conferenceId, Config::getVar('general', 'registry_dir') . '/conferenceSettings.xml', array('privacyStatementUrl' => Request::url($this->getData('conferencePath'), 'index', 'about', 'submissions', null, null, 'privacyStatement'), 'loginUrl' => Request::url('index', 'index', 'login'), 'conferenceUrl' => Request::url($this->getData('conferencePath'), null), 'conferencePath' => $this->getData('conferencePath'), 'primaryLocale' => $site->getPrimaryLocale(), 'aboutUrl' => Request::url($this->getData('conferencePath'), 'index', 'about', null), 'accountUrl' => Request::url($this->getData('conferencePath'), 'index', 'user', 'register'), 'conferenceName' => $titles[$site->getPrimaryLocale()]));
         // Install the default RT versions.
         import('rt.ocs.ConferenceRTAdmin');
         $conferenceRtAdmin = new ConferenceRTAdmin($conferenceId);
         $conferenceRtAdmin->restoreVersions(false);
     }
     $conference->updateSetting('title', $this->getData('title'), 'string', true);
     $conference->updateSetting('description', $this->getData('description'), 'string', true);
     // Make sure all plugins are loaded for settings preload
     PluginRegistry::loadAllPlugins();
     HookRegistry::call('ConferenceSiteSettingsForm::execute', array(&$this, &$conference));
 }
Ejemplo n.º 30
0
 /**
  * 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;
 }