/** * Update user's roles. * @param $args array * @param $request PKPRequest */ function execute($args, $request) { parent::execute($request); // Role management handled by parent form, just return user. $userDao = DAORegistry::getDAO('UserDAO'); return $userDao->getById($this->userId); }
/** * Create or update a user. * @param $args array * @param $request PKPRequest */ function &execute($args, $request) { parent::execute($request); $userDao = DAORegistry::getDAO('UserDAO'); $context = $request->getContext(); if (isset($this->userId)) { $userId = $this->userId; $user = $userDao->getById($userId); } if (!isset($user)) { $user = $userDao->newDataObject(); $user->setInlineHelp(1); // default new users to having inline help visible } $user->setSalutation($this->getData('salutation')); $user->setFirstName($this->getData('firstName')); $user->setMiddleName($this->getData('middleName')); $user->setLastName($this->getData('lastName')); $user->setSuffix($this->getData('suffix')); $user->setInitials($this->getData('initials')); $user->setGender($this->getData('gender')); $user->setAffiliation($this->getData('affiliation'), null); // Localized $user->setSignature($this->getData('signature'), null); // Localized $user->setEmail($this->getData('email')); $user->setUrl($this->getData('userUrl')); $user->setPhone($this->getData('phone')); $user->setOrcid($this->getData('orcid')); $user->setMailingAddress($this->getData('mailingAddress')); $user->setCountry($this->getData('country')); $user->setBiography($this->getData('biography'), null); // Localized $user->setMustChangePassword($this->getData('mustChangePassword') ? 1 : 0); $user->setAuthId((int) $this->getData('authId')); $site = $request->getSite(); $availableLocales = $site->getSupportedLocales(); $locales = array(); foreach ($this->getData('userLocales') as $locale) { if (AppLocale::isLocaleValid($locale) && in_array($locale, $availableLocales)) { array_push($locales, $locale); } } $user->setLocales($locales); if ($user->getAuthId()) { $authDao = DAORegistry::getDAO('AuthSourceDAO'); $auth =& $authDao->getPlugin($user->getAuthId()); } if ($user->getId() != null) { if ($this->getData('password') !== '') { if (isset($auth)) { $auth->doSetUserPassword($user->getUsername(), $this->getData('password')); $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword())); // Used for PW reset hash only } else { $user->setPassword(Validation::encryptCredentials($user->getUsername(), $this->getData('password'))); } } if (isset($auth)) { // FIXME Should try to create user here too? $auth->doSetUserInfo($user); } $userDao->updateObject($user); } else { $user->setUsername($this->getData('username')); if ($this->getData('generatePassword')) { $password = Validation::generatePassword(); $sendNotify = true; } else { $password = $this->getData('password'); $sendNotify = $this->getData('sendNotify'); } if (isset($auth)) { $user->setPassword($password); // FIXME Check result and handle failures $auth->doCreateUser($user); $user->setAuthId($auth->authId); $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword())); // Used for PW reset hash only } else { $user->setPassword(Validation::encryptCredentials($this->getData('username'), $password)); } $user->setDateRegistered(Core::getCurrentDate()); $userId = $userDao->insertObject($user); if ($sendNotify) { // Send welcome email to user import('lib.pkp.classes.mail.MailTemplate'); $mail = new MailTemplate('USER_REGISTER'); $mail->setReplyTo($context->getSetting('contactEmail'), $context->getSetting('contactName')); $mail->assignParams(array('username' => $this->getData('username'), 'password' => $password, 'userFullName' => $user->getFullName())); $mail->addRecipient($user->getEmail(), $user->getFullName()); $mail->send(); } } import('lib.pkp.classes.user.InterestManager'); $interestManager = new InterestManager(); $interestManager->setInterestsForUser($user, $this->getData('interests')); return $user; }
/** * Update an existing user * @param $args array * @param $request PKPRequest * @return string Serialized JSON object */ function updateUser($args, &$request) { // Identify the press $press =& $request->getPress(); // Identify the user Id $userId = $request->getUserVar('userId'); if ($userId !== null && !Validation::canAdminister($press->getId(), $userId)) { // We don't have administrative rights over this user. $json = new JSON('false', Locale::translate('grid.user.cannotAdminister')); } else { // Form handling import('controllers.grid.users.user.form.UserForm'); $userForm = new UserForm($userId); $userForm->readInputData(); if ($userForm->validate()) { $user =& $userForm->execute($args, $request); // If this is a newly created user, show role management form if (!$userId) { import('controllers.grid.users.user.form.UserRoleForm'); $userRoleForm = new UserRoleForm($user->getId()); $userRoleForm->initData($args, $request); $json = new JSON('false', $userRoleForm->display($args, $request)); } else { // Successful edit of an existing user // Prepare the grid row data $row =& $this->getRowInstance(); $row->setGridId($this->getId()); $row->setId($user->getId()); $row->setData($user); $row->initialize($request); $json = new JSON('true', $this->_renderRowInternally($request, $row)); } } else { $json = new JSON('false', $userForm->display($args, $request)); } } return $json->getString(); }