/** * Save profile settings. */ function execute() { $user =& Request::getUser(); $user->setSalutation($this->getData('salutation')); $user->setFirstName($this->getData('firstName')); $user->setMiddleName($this->getData('middleName')); $user->setLastName($this->getData('lastName')); $user->setGender($this->getData('gender')); $user->setInitials($this->getData('initials')); $user->setAffiliation($this->getData('affiliation'), null); // Localized $user->setSignature($this->getData('signature'), null); // Localized $user->setEmail($this->getData('email')); $user->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 $userId = $user->getId(); // Insert the user interests import('lib.pkp.classes.user.InterestManager'); $interestManager = new InterestManager(); $interestManager->insertInterests($userId, $this->getData('interestsKeywords'), $this->getData('interests')); $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); $userDao =& DAORegistry::getDAO('UserDAO'); $userDao->updateObject($user); $roleDao =& DAORegistry::getDAO('RoleDAO'); $journalDao =& DAORegistry::getDAO('JournalDAO'); // Roles $journal =& Request::getJournal(); if ($journal) { $role = new Role(); $role->setUserId($user->getId()); $role->setJournalId($journal->getId()); if ($journal->getSetting('allowRegReviewer')) { $role->setRoleId(ROLE_ID_REVIEWER); $hasRole = Validation::isReviewer(); $wantsRole = Request::getUserVar('reviewerRole'); if ($hasRole && !$wantsRole) { $roleDao->deleteRole($role); } if (!$hasRole && $wantsRole) { $roleDao->insertRole($role); } } if ($journal->getSetting('allowRegAuthor')) { $role->setRoleId(ROLE_ID_AUTHOR); $hasRole = Validation::isAuthor(); $wantsRole = Request::getUserVar('authorRole'); if ($hasRole && !$wantsRole) { $roleDao->deleteRole($role); } if (!$hasRole && $wantsRole) { $roleDao->insertRole($role); } } if ($journal->getSetting('allowRegReader')) { $role->setRoleId(ROLE_ID_READER); $hasRole = Validation::isReader(); $wantsRole = Request::getUserVar('readerRole'); if ($hasRole && !$wantsRole) { $roleDao->deleteRole($role); } if (!$hasRole && $wantsRole) { $roleDao->insertRole($role); } } } $openAccessNotify = Request::getUserVar('openAccessNotify'); $userSettingsDao =& DAORegistry::getDAO('UserSettingsDAO'); $journals =& $journalDao->getEnabledJournals(); $journals =& $journals->toArray(); foreach ($journals as $thisJournal) { if ($thisJournal->getSetting('publishingMode') == PUBLISHING_MODE_SUBSCRIPTION && $thisJournal->getSetting('enableOpenAccessNotification')) { $currentlyReceives = $user->getSetting('openAccessNotification', $thisJournal->getJournalId()); $shouldReceive = !empty($openAccessNotify) && in_array($thisJournal->getJournalId(), $openAccessNotify); if ($currentlyReceives != $shouldReceive) { $userSettingsDao->updateSetting($user->getId(), 'openAccessNotification', $shouldReceive, 'bool', $thisJournal->getJournalId()); } } } if ($user->getAuthId()) { $authDao =& DAORegistry::getDAO('AuthSourceDAO'); $auth =& $authDao->getPlugin($user->getAuthId()); } if (isset($auth)) { $auth->doSetUserInfo($user); } }
/** * Register a new user. */ 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); } }
/** * Save profile settings. */ function execute() { $user =& Request::getUser(); $user->setSalutation($this->getData('salutation')); $user->setFirstName($this->getData('firstName')); $user->setMiddleName($this->getData('middleName')); $user->setLastName($this->getData('lastName')); $user->setGender($this->getData('gender')); $user->setInitials($this->getData('initials')); $user->setAffiliation($this->getData('affiliation'), null); // Localized $user->setSignature($this->getData('signature'), null); // Localized $user->setEmail($this->getData('email')); $user->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 // Add reviewing interests to interests table import('lib.pkp.classes.user.InterestManager'); $interestManager = new InterestManager(); $interestManager->insertInterests($userId, $this->getData('interestsKeywords'), $this->getData('interests')); $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); $userDao =& DAORegistry::getDAO('UserDAO'); $userDao->updateObject($user); $userGroupDao =& DAORegistry::getDAO('UserGroupDAO'); $pressDao =& DAORegistry::getDAO('PressDAO'); $notificationStatusDao =& DAORegistry::getDAO('NotificationStatusDAO'); // Roles $press =& Request::getPress(); if ($press) { if ($press->getSetting('allowRegReviewer')) { foreach ($this->getData('reviewerGroup') as $groupId => $wantsGroup) { $inGroup = $userGroupDao->userInGroup($user->getId(), $groupId); if ($inGroup && !$wantsGroup) { $userGroupDao->removeUserFromGroup($user->getId(), $groupId); } if (!$hasRole && $wantsRole) { $userGroupDao->assignUserToGroup($user->getId(), $groupId); } } } if ($press->getSetting('allowRegAuthor')) { foreach ($this->getData('authorGroup') as $groupId => $wantsGroup) { $inGroup = $userGroupDao->userInGroup($user->getId(), $groupId); if ($inGroup && !$wantsGroup) { $userGroupDao->removeUserFromGroup($user->getId(), $groupId); } if (!$hasRole && $wantsRole) { $userGroupDao->assignUserToGroup($user->getId(), $groupId); } } } if ($press->getSetting('allowRegReader')) { foreach ($this->getData('readerGroup') as $groupId => $wantsGroup) { $inGroup = $userGroupDao->userInGroup($user->getId(), $groupId); if ($inGroup && !$wantsGroup) { $userGroupDao->removeUserFromGroup($user->getId(), $groupId); } if (!$hasRole && $wantsRole) { $userGroupDao->assignUserToGroup($user->getId(), $groupId); } } } } $presses =& $pressDao->getPresses(); $presses =& $presses->toArray(); $pressNotifications = $notificationStatusDao->getPressNotifications($user->getId()); $readerNotify = Request::getUserVar('pressNotify'); foreach ($presses as $thisPress) { $thisPressId = $thisPress->getId(); $currentlyReceives = !empty($pressNotifications[$thisPressId]); $shouldReceive = !empty($readerNotify) && in_array($thisPress->getId(), $readerNotify); if ($currentlyReceives != $shouldReceive) { $notificationStatusDao->setPressNotifications($thisPressId, $user->getId(), $shouldReceive); } } $userSettingsDao =& DAORegistry::getDAO('UserSettingsDAO'); if ($user->getAuthId()) { $authDao =& DAORegistry::getDAO('AuthSourceDAO'); $auth =& $authDao->getPlugin($user->getAuthId()); } if (isset($auth)) { $auth->doSetUserInfo($user); } }
/** * Create or update a user. * @param $args array * @param $request PKPRequest */ function &execute($args, &$request) { $userDao =& DAORegistry::getDAO('UserDAO'); $press =& $request->getPress(); if (isset($this->userId)) { $userId = $this->userId; $user =& $userDao->getUser($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) { 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->insertUser($user); if ($sendNotify) { // Send welcome email to user import('classes.mail.MailTemplate'); $mail = new MailTemplate('USER_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(); } } // Add reviewing interests to interests table import('lib.pkp.classes.user.InterestManager'); $interestManager = new InterestManager(); $interestManager->insertInterests($userId, $this->getData('interestsKeywords'), $this->getData('interests')); return $user; }
/** * Register a new user. * @return userId int */ function execute() { $userDao =& DAORegistry::getDAO('UserDAO'); $user = new User(); $user->setSalutation($this->getData('salutation')); $user->setFirstName($this->getData('firstName')); $user->setMiddleName($this->getData('middleName')); $user->setLastName($this->getData('lastName')); $user->setGender($this->getData('gender')); $user->setInitials($this->getData('initials')); $user->setAffiliation($this->getData('affiliation'), null); // Localized $user->setEmail($this->getData('email')); $user->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); // Insert the user interests import('lib.pkp.classes.user.InterestManager'); $interestManager = new InterestManager(); $interestManager->insertInterests($userId, $this->getData('interestsKeywords'), $this->getData('interests')); $roleDao =& DAORegistry::getDAO('RoleDAO'); $journal =& Request::getJournal(); $role = new Role(); $role->setJournalId($journal->getId()); $role->setUserId($userId); $role->setRoleId(ROLE_ID_REVIEWER); $roleDao->insertRole($role); if ($sendNotify) { // Send welcome email to user import('classes.mail.MailTemplate'); $mail = new MailTemplate('REVIEWER_REGISTER'); $mail->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(); } return $userId; }
/** * 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(); // FIXME: Bug #6199 $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 reviewing interests to interests table import('lib.pkp.classes.user.InterestManager'); $interestManager = new InterestManager(); $interestManager->insertInterests($userId, $this->getData('interestsKeywords'), $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('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 = new SeriesEditorAction(); $seriesEditorAction->addReviewer($submission, $reviewerId, $reviewType, $round, $reviewDueDate, $responseDueDate); // Get the reviewAssignment object now that it has been added $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO'); /* @var $reviewAssignmentDao 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; }