/**
  * Register a new user.
  */
 function execute()
 {
     $userDao =& DAORegistry::getDAO('UserDAO');
     $journal =& Request::getJournal();
     if (isset($this->userId)) {
         $user =& $userDao->getUser($this->userId);
     }
     if (!isset($user)) {
         $user = new User();
     }
     $user->setSalutation($this->getData('salutation'));
     $user->setFirstName($this->getData('firstName'));
     $user->setMiddleName($this->getData('middleName'));
     $user->setLastName($this->getData('lastName'));
     $user->setInitials($this->getData('initials'));
     $user->setGender($this->getData('gender'));
     $user->setAffiliation($this->getData('affiliation'), null);
     // Localized
     $user->setSignature($this->getData('signature'), null);
     // Localized
     $user->setEmail($this->getData('email'));
     $user->setUrl($this->getData('userUrl'));
     $user->setPhone($this->getData('phone'));
     $user->setFax($this->getData('fax'));
     $user->setMailingAddress($this->getData('mailingAddress'));
     $user->setCountry($this->getData('country'));
     $user->setBiography($this->getData('biography'), null);
     // Localized
     $user->setGossip($this->getData('gossip'), null);
     // Localized
     $user->setMustChangePassword($this->getData('mustChangePassword') ? 1 : 0);
     $user->setAuthId((int) $this->getData('authId'));
     $site =& Request::getSite();
     $availableLocales = $site->getSupportedLocales();
     $locales = array();
     foreach ($this->getData('userLocales') as $locale) {
         if (Locale::isLocaleValid($locale) && in_array($locale, $availableLocales)) {
             array_push($locales, $locale);
         }
     }
     $user->setLocales($locales);
     if ($user->getAuthId()) {
         $authDao =& DAORegistry::getDAO('AuthSourceDAO');
         $auth =& $authDao->getPlugin($user->getAuthId());
     }
     if ($user->getId() != null) {
         $userId = $user->getId();
         if ($this->getData('password') !== '') {
             if (isset($auth)) {
                 $auth->doSetUserPassword($user->getUsername(), $this->getData('password'));
                 $user->setPassword(Validation::encryptCredentials($userId, Validation::generatePassword()));
                 // Used for PW reset hash only
             } else {
                 $user->setPassword(Validation::encryptCredentials($user->getUsername(), $this->getData('password')));
             }
         }
         if (isset($auth)) {
             // FIXME Should try to create user here too?
             $auth->doSetUserInfo($user);
         }
         $userDao->updateObject($user);
     } else {
         $user->setUsername($this->getData('username'));
         if ($this->getData('generatePassword')) {
             $password = Validation::generatePassword();
             $sendNotify = true;
         } else {
             $password = $this->getData('password');
             $sendNotify = $this->getData('sendNotify');
         }
         if (isset($auth)) {
             $user->setPassword($password);
             // FIXME Check result and handle failures
             $auth->doCreateUser($user);
             $user->setAuthId($auth->authId);
             $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword()));
             // Used for PW reset hash only
         } else {
             $user->setPassword(Validation::encryptCredentials($this->getData('username'), $password));
         }
         $user->setDateRegistered(Core::getCurrentDate());
         $userId = $userDao->insertUser($user);
         $isManager = Validation::isJournalManager();
         // EL on March 13th 2013
         // If this is used, it should be totally modified
         if (!empty($this->_data['enrollAs'])) {
             foreach ($this->getData('enrollAs') as $roleName) {
                 // Enroll new user into an initial role
                 $roleDao =& DAORegistry::getDAO('RoleDAO');
                 $roleId = $roleDao->getRoleIdFromPath($roleName);
                 if (!$isManager && $roleId != ROLE_ID_READER) {
                     continue;
                 }
                 if ($roleId != null) {
                     $role = new Role();
                     $role->setJournalId($journal->getId());
                     $role->setUserId($userId);
                     $role->setRoleId($roleId);
                     $roleDao->insertRole($role);
                 }
             }
         }
         if ($sendNotify) {
             // Send welcome email to user
             import('classes.mail.MailTemplate');
             $mail = new MailTemplate('USER_REGISTER');
             $mail->setFrom($journal->getSetting('supportEmail'), $journal->getSetting('supportName'));
             $mail->assignParams(array('username' => $this->getData('username'), 'password' => String::substr($this->getData('password'), 0, 30), 'supportName' => $journal->getSetting('supportName'), 'userFullName' => $user->getFullName()));
             $mail->addRecipient($user->getEmail(), $user->getFullName());
             $mail->send();
         }
     }
     // Add reviewing interests to interests table
     $interestDao =& DAORegistry::getDAO('InterestDAO');
     $interests = is_array(Request::getUserVar('interestsKeywords')) ? Request::getUserVar('interestsKeywords') : array();
     if (is_array($interests)) {
         $interests = array_map('urldecode', $interests);
         // The interests are coming in encoded -- Decode them for DB storage
         $interestTextOnly = Request::getUserVar('interests');
         if (!empty($interestsTextOnly)) {
             // If JS is disabled, this will be the input to read
             $interestsTextOnly = explode(",", $interestTextOnly);
         } else {
             $interestsTextOnly = null;
         }
         if ($interestsTextOnly && !isset($interests)) {
             $interests = $interestsTextOnly;
         } elseif (isset($interests) && !is_array($interests)) {
             $interests = array($interests);
         }
         $interestDao->insertInterests($interests, $userId, true);
     }
 }
Example #2
0
 /**
  * Register a new user.
  */
 function execute()
 {
     $userDao =& DAORegistry::getDAO('UserDAO');
     $conference =& Request::getConference();
     $schedConf =& Request::getSchedConf();
     if (isset($this->userId)) {
         $user =& $userDao->getUser($this->userId);
     }
     if (!isset($user)) {
         $user = new User();
     }
     $user->setSalutation($this->getData('salutation'));
     $user->setFirstName($this->getData('firstName'));
     $user->setMiddleName($this->getData('middleName'));
     $user->setLastName($this->getData('lastName'));
     $user->setInitials($this->getData('initials'));
     $user->setGender($this->getData('gender'));
     $user->setAffiliation($this->getData('affiliation'));
     $user->setEmail($this->getData('email'));
     $user->setUrl($this->getData('userUrl'));
     $user->setPhone($this->getData('phone'));
     $user->setFax($this->getData('fax'));
     $user->setMailingAddress($this->getData('mailingAddress'));
     $user->setCountry($this->getData('country'));
     $user->setBiography($this->getData('biography'), null);
     // Localized
     $user->setInterests($this->getData('interests'), null);
     // Localized
     $user->setGossip($this->getData('gossip'), null);
     // Localized
     $user->setSignature($this->getData('signature'), 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->insertUser($user);
         if (!empty($this->_data['enrollAs'])) {
             foreach ($this->getData('enrollAs') as $roleName) {
                 // Enroll new user into an initial role
                 $roleDao =& DAORegistry::getDAO('RoleDAO');
                 $roleId = $roleDao->getRoleIdFromPath($roleName);
                 if ($roleId != null) {
                     $role = new Role();
                     $role->setConferenceId($conference->getId());
                     $role->setSchedConfId($schedConf ? $schedConf->getId() : 0);
                     $role->setUserId($userId);
                     $role->setRoleId($roleId);
                     $roleDao->insertRole($role);
                 }
             }
         }
         if ($sendNotify) {
             // Send welcome email to user
             import('mail.MailTemplate');
             $mail = new MailTemplate('USER_REGISTER');
             if ($schedConf) {
                 $mail->setFrom($schedConf->getSetting('contactEmail'), $schedConf->getSetting('contactName'));
             } elseif ($conference) {
                 $mail->setFrom($conference->getSetting('contactEmail'), $conference->getSetting('contactName'));
             } else {
                 $site =& Request::getSite();
                 $mail->setFrom($site->getContactEmail(), $site->getContactName());
             }
             $mail->assignParams(array('username' => $this->getData('username'), 'password' => $password));
             $mail->addRecipient($user->getEmail(), $user->getFullName());
             $mail->send();
         }
     }
 }
Example #3
0
 /**
  * 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;
 }