16 import(
'lib.pkp.controllers.grid.settings.user.form.UserForm');
33 parent::__construct(
'controllers/grid/settings/user/form/userDetailsForm.tpl',
$userId);
43 $site = $request->getSite();
49 $this->
addCheck(
new FormValidator($this,
'username',
'required',
'user.profile.form.usernameRequired'));
54 $this->
addCheck(
new FormValidator($this,
'password',
'required',
'user.profile.form.passwordRequired'));
55 $this->
addCheck(
new FormValidatorCustom($this,
'password',
'required',
'user.register.form.passwordLengthRestriction',
function($password) use ($form, $site) {
56 return $form->getData(
'generatePassword') ||
PKPString::strlen($password) >= $site->getMinPasswordLength();
57 }, array(),
false, array(
'length' => $site->getMinPasswordLength())));
58 $this->
addCheck(
new FormValidatorCustom($this,
'password',
'required',
'user.register.form.passwordsDoNotMatch',
function($password) use ($form) {
59 return $password == $form->getData(
'password2');
64 $this->user = $userDao->getById(
$userId);
66 $this->
addCheck(
new FormValidatorCustom($this,
'password',
'optional',
'user.register.form.passwordLengthRestriction',
function($password) use ($form, $site) {
67 return $form->getData(
'generatePassword') ||
PKPString::strlen($password) >= $site->getMinPasswordLength();
68 }, array(),
false, array(
'length' => $site->getMinPasswordLength())));
69 $this->
addCheck(
new FormValidatorCustom($this,
'password',
'optional',
'user.register.form.passwordsDoNotMatch',
function($password) use ($form) {
70 return $password == $form->getData(
'password2');
73 $this->
addCheck(
new FormValidatorLocale($this,
'givenName',
'required',
'user.profile.form.givenNameRequired', $site->getPrimaryLocale()));
74 $this->
addCheck(
new FormValidatorCustom($this,
'familyName',
'optional',
'user.profile.form.givenNameRequired.locale',
function($familyName) use ($form) {
75 $givenNames = $form->getData(
'givenName');
76 foreach ($familyName as $locale => $value) {
77 if (!empty($value) && empty($givenNames[$locale])) {
96 $context = $request->getContext();
97 $contextId = $context ? $context->getId() : CONTEXT_ID_NONE;
101 if (isset($this->user)) {
104 import(
'lib.pkp.classes.user.InterestManager');
108 'authId' =>
$user->getAuthId(),
109 'username' =>
$user->getUsername(),
110 'givenName' =>
$user->getGivenName(
null),
111 'familyName' =>
$user->getFamilyName(
null),
112 'preferredPublicName' =>
$user->getPreferredPublicName(
null),
113 'signature' =>
$user->getSignature(
null),
114 'affiliation' =>
$user->getAffiliation(
null),
115 'email' =>
$user->getEmail(),
116 'userUrl' =>
$user->getUrl(),
117 'phone' =>
$user->getPhone(),
118 'orcid' =>
$user->getOrcid(),
119 'mailingAddress' =>
$user->getMailingAddress(),
120 'country' =>
$user->getCountry(),
121 'biography' =>
$user->getBiography(
null),
122 'interests' => $interestManager->getInterestsForUser(
$user),
123 'userLocales' =>
$user->getLocales(),
125 import(
'classes.core.Services');
127 $data[
'canCurrentUserGossip'] = $userService->canCurrentUserGossip(
$user->getId());
128 if ($data[
'canCurrentUserGossip']) {
129 $data[
'gossip'] =
$user->getGossip();
131 }
else if (isset($this->author)) {
134 'givenName' =>
$author->getGivenName(
null),
135 'familyName' =>
$author->getFamilyName(
null),
136 'affiliation' =>
$author->getAffiliation(
null),
137 'preferredPublicName' =>
$author->getPreferredPublicName(
null),
138 'email' =>
$author->getEmail(),
139 'userUrl' =>
$author->getUrl(),
140 'orcid' =>
$author->getOrcid(),
141 'country' =>
$author->getCountry(),
142 'biography' =>
$author->getBiography(
null),
146 'mustChangePassword' =>
true,
149 foreach($data as $key => $value) {
159 function display($request =
null, $template =
null) {
160 $site = $request->getSite();
161 $isoCodes = new \Sokil\IsoCodes\IsoCodesFactory();
162 $countries = array();
163 foreach ($isoCodes->getCountries() as $country) {
164 $countries[$country->getAlpha2()] = $country->getLocalName();
169 $templateMgr->assign(array(
170 'minPasswordLength' => $site->getMinPasswordLength(),
171 'source' => $request->getUserVar(
'source'),
172 'userId' => $this->userId,
173 'sitePrimaryLocale' => $site->getPrimaryLocale(),
174 'availableLocales' => $site->getSupportedLocaleNames(),
175 'countries' => $countries,
178 if (isset($this->user)) {
179 $templateMgr->assign(
'username', $this->user->getUsername());
183 $authSources = $authDao->getSources();
184 $authSourceOptions = array();
185 foreach ($authSources->toArray() as $auth) {
186 $authSourceOptions[$auth->getAuthId()] = $auth->getTitle();
188 if (!empty($authSourceOptions)) {
189 $templateMgr->assign(
'authSourceOptions', $authSourceOptions);
192 return parent::display($request, $template);
201 parent::readInputData();
209 'preferredPublicName',
226 if ($this->userId ==
null) {
230 if ($this->
getData(
'userLocales') ==
null || !is_array($this->
getData(
'userLocales'))) {
231 $this->
setData(
'userLocales', array());
240 return $userDao->getLocaleFieldNames();
246 function execute(...$functionParams) {
249 $context = $request->getContext();
251 if (!isset($this->user)) {
252 $this->user = $userDao->newDataObject();
253 $this->user->setInlineHelp(1);
256 $this->user->setGivenName($this->
getData(
'givenName'),
null);
257 $this->user->setFamilyName($this->
getData(
'familyName'),
null);
258 $this->user->setPreferredPublicName($this->
getData(
'preferredPublicName'),
null);
259 $this->user->setAffiliation($this->
getData(
'affiliation'),
null);
260 $this->user->setSignature($this->
getData(
'signature'),
null);
261 $this->user->setEmail($this->
getData(
'email'));
262 $this->user->setUrl($this->
getData(
'userUrl'));
263 $this->user->setPhone($this->
getData(
'phone'));
264 $this->user->setOrcid($this->
getData(
'orcid'));
265 $this->user->setMailingAddress($this->
getData(
'mailingAddress'));
266 $this->user->setCountry($this->
getData(
'country'));
267 $this->user->setBiography($this->
getData(
'biography'),
null);
268 $this->user->setMustChangePassword($this->
getData(
'mustChangePassword') ? 1 : 0);
269 $this->user->setAuthId((
int) $this->
getData(
'authId'));
271 import(
'classes.core.Services');
273 if ($userService->canCurrentUserGossip($this->user->getId())) {
274 $this->user->setGossip($this->
getData(
'gossip'));
277 $site = $request->getSite();
278 $availableLocales = $site->getSupportedLocales();
281 foreach ($this->
getData(
'userLocales') as $locale) {
283 array_push($locales, $locale);
286 $this->user->setLocales($locales);
288 if ($this->user->getAuthId()) {
290 $auth =& $authDao->getPlugin($this->user->getAuthId());
293 parent::execute(...$functionParams);
295 if ($this->user->getId() !=
null) {
296 if ($this->
getData(
'password') !==
'') {
298 $auth->doSetUserPassword($this->user->getUsername(), $this->getData(
'password'));
307 $auth->doSetUserInfo($this->user);
310 $userDao->updateObject($this->user);
313 $this->user->setUsername($this->
getData(
'username'));
314 if ($this->
getData(
'generatePassword')) {
318 $password = $this->
getData(
'password');
319 $sendNotify = $this->
getData(
'sendNotify');
323 $this->user->setPassword($password);
325 $auth->doCreateUser($this->user);
326 $this->user->setAuthId($auth->authId);
333 $userId = $userDao->insertObject($this->user);
337 import(
'lib.pkp.classes.mail.MailTemplate');
339 $mail->setReplyTo($context->getData(
'contactEmail'), $context->getData(
'contactName'));
340 $mail->assignParams(array(
'username' => $this->
getData(
'username'),
'password' => $password,
'userFullName' => $this->user->getFullName()));
341 $mail->addRecipient($this->user->getEmail(), $this->user->getFullName());
342 if (!$mail->send()) {
343 import(
'classes.notification.NotificationManager');
345 $notificationMgr->createTrivialNotification($request->getUser()->getId(), NOTIFICATION_TYPE_ERROR, array(
'contents' => __(
'email.compose.error')));
350 import(
'lib.pkp.classes.user.InterestManager');
352 $interestManager->setInterestsForUser($this->user, $this->
getData(
'interests'));