/** * Save profile * * @return void */ private function _saveEntryData() { $isNew = !$this->_profile->get('uidNumber'); if (!isset($this->raw->password)) { $this->raw->password = null; } if ($isNew) { if (!$this->_profile->get('username')) { $valid = false; // Try to create from name $username = preg_replace('/[^a-z9-0_]/i', '', strtolower($this->_profile->get('name'))); if (\Hubzero\Utility\Validate::username($username)) { if (!$this->_usernameExists($username)) { $valid = true; } } // Try to create from portion preceeding @ in email address if (!$valid) { $username = strstr($this->_profile->get('email'), '@', true); if (\Hubzero\Utility\Validate::username($username)) { if ($this->_usernameExists($username)) { $valid = true; } } } // Try to create from whole email address if (!$valid) { for ($i = 0; $i <= 99; $i++) { $username = preg_replace('/[^a-z9-0_]/i', '', strtolower($this->_profile->get('name'))) . $i; if (\Hubzero\Utility\Validate::username($username)) { if ($this->_usernameExists($username)) { $valid = true; break; } } } } if ($valid) { $this->_profile->set('username', $username); } } if (!$this->raw->password) { //\Hubzero\User\Helper::random_password(); $this->raw->password = $this->_profile->get('username'); } $usersConfig = Component::params('com_users'); $newUsertype = $usersConfig->get('new_usertype'); if (!$newUsertype) { $db = \App::get('db'); $query = $db->getQuery(true)->select('id')->from('#__usergroups')->where('title = "Registered"'); $db->setQuery($query); $newUsertype = $db->loadResult(); } $user = User::getRoot(); $user->set('username', $this->_profile->get('username')); $user->set('name', $this->_profile->get('name')); $user->set('email', $this->_profile->get('email')); $user->set('id', 0); $user->set('groups', array($newUsertype)); $user->set('registerDate', Date::of('now')->toSql()); $user->set('password', $this->raw->password); $user->set('password_clear', $this->raw->password); $user->save(); $user->set('password_clear', ''); // Attempt to get the new user $profile = \Hubzero\User\Profile::getInstance($user->get('id')); $result = is_object($profile); // Did we successfully create an account? if ($result) { if (!$this->record->entry->get('emailConfirmed', null)) { $this->_profile->set('emailConfirmed', -rand(1, pow(2, 31) - 1)); } $this->_profile->set('uidNumber', $user->get('id')); $this->_profile->set('gidNumber', $profile->get('gidNumber')); if (!$this->_profile->get('homeDirectory')) { $this->_profile->set('homeDirectory', $profile->get('homeDirectory')); } if (!$this->_profile->get('loginShell')) { $this->_profile->set('loginShell', $profile->get('loginShell')); } if (!$this->_profile->get('ftpShell')) { $this->_profile->set('ftpShell', $profile->get('ftpShell')); } if (!$this->_profile->get('jobsAllowed')) { $this->_profile->set('jobsAllowed', $profile->get('jobsAllowed')); } } } if (!$this->_profile->store()) { throw new Exception(Lang::txt('Unable to save the entry data.')); } if ($password = $this->raw->password) { /*if ($isNew) { // We need to bypass any hashing $this->raw->password = '******'; \Hubzero\User\Password::changePasshash($this->_profile->get('uidNumber'), $password); } else {*/ \Hubzero\User\Password::changePassword($this->_profile->get('uidNumber'), $password); //} } \Hubzero\User\Password::expirePassword($this->_profile->get('uidNumber')); if ($isNew && $this->_options['emailnew'] == 1) { $eview = new \Hubzero\Component\View(array('base_path' => PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'site', 'name' => 'emails', 'layout' => 'confirm')); $eview->option = 'com_members'; $eview->controller = 'register'; $eview->sitename = Config::get('sitename'); $eview->login = $this->_profile->get('username'); $eview->name = $this->_profile->get('name'); $eview->registerDate = $this->_profile->get('registerDate'); $eview->confirm = $this->_profile->get('emailConfirmed'); $eview->baseURL = Request::base(); $msg = new \Hubzero\Mail\Message(); $msg->setSubject(Config::get('sitename') . ' ' . Lang::txt('COM_MEMBERS_REGISTER_EMAIL_CONFIRMATION'))->addTo($this->_profile->get('email'))->addFrom(Config::get('mailfrom'), Config::get('sitename') . ' Administrator')->addHeader('X-Component', 'com_members'); $message = $eview->loadTemplate(); $message = str_replace("\n", "\r\n", $message); $msg->addPart($message, 'text/plain'); $eview->setLayout('confirm_html'); $message = $eview->loadTemplate(); $message = str_replace("\n", "\r\n", $message); $msg->addPart($message, 'text/html'); if (!$msg->send()) { array_push($this->record->errors, Lang::txt('COM_MEMBERS_REGISTER_ERROR_EMAILING_CONFIRMATION')); } } }
/** * Save profile * * @return void */ private function _saveEntryData() { $isNew = !$this->record->entry->get('id'); if (!isset($this->raw->password)) { $this->raw->password = null; } if ($isNew) { if (!$this->record->entry->get('username')) { $valid = false; // Try to create from name $username = preg_replace('/[^a-z9-0_]/i', '', strtolower($this->record->entry->get('name'))); if (Validate::username($username)) { if (!$this->_usernameExists($username)) { $valid = true; } } // Try to create from portion preceeding @ in email address if (!$valid) { $username = strstr($this->record->entry->get('email'), '@', true); if (Validate::username($username)) { if ($this->_usernameExists($username)) { $valid = true; } } } // Try to create from whole email address if (!$valid) { for ($i = 0; $i <= 99; $i++) { $username = preg_replace('/[^a-z9-0_]/i', '', strtolower($this->record->entry->get('name'))) . $i; if (Validate::username($username)) { if ($this->_usernameExists($username)) { $valid = true; break; } } } } if ($valid) { $this->record->entry->set('username', $username); } } if (!$this->raw->password) { $this->raw->password = $this->record->entry->get('username'); } $newUsertype = null; if (isset($this->raw->usertype)) { if (is_numeric($this->raw->usertype)) { $newUsertype = (int) $this->raw->usertype; } else { $db = \App::get('db'); $query = $db->getQuery(true)->select('id')->from('#__usergroups')->where('title=' . $db->quote($this->raw->usertype)); $db->setQuery($query); $newUsertype = (int) $db->loadResult(); } } if (!$newUsertype) { $usersConfig = Component::params('com_users'); $newUsertype = $usersConfig->get('new_usertype'); if (!$newUsertype) { $db = \App::get('db'); $query = $db->getQuery(true)->select('id')->from('#__usergroups')->where('title = "Registered"'); $db->setQuery($query); $newUsertype = $db->loadResult(); } } $d = Date::of('now'); if ($this->raw->registerDate) { try { $d = Date::of($this->raw->registerDate); } catch (Exception $e) { array_push($this->record->errors, $e->getMessage()); } } $this->record->entry->set('id', 0); $this->record->entry->set('accessgroups', array($newUsertype)); $this->record->entry->set('registerDate', $d->toSql()); $this->record->entry->set('password', $this->raw->password); if (!$this->record->entry->get('activation', null)) { $this->record->entry->set('activation', -rand(1, pow(2, 31) - 1)); } } if (!$this->record->entry->save()) { throw new Exception(Lang::txt('Unable to save the entry data.')); } if (!empty($this->_profile)) { if (!$this->record->entry->saveProfile($this->_profile)) { throw new Exception($this->record->entry->getError()); } } if ($this->raw->password) { \Hubzero\User\Password::changePassword($this->record->entry->get('id'), $this->raw->password); \Hubzero\User\Password::expirePassword($this->record->entry->get('id')); } if ($isNew && $this->_options['emailnew'] == 1) { $eview = new \Hubzero\Component\View(array('base_path' => PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'site', 'name' => 'emails', 'layout' => 'confirm')); $eview->option = 'com_members'; $eview->controller = 'register'; $eview->sitename = Config::get('sitename'); $eview->login = $this->record->entry->get('username'); $eview->name = $this->record->entry->get('name'); $eview->registerDate = $this->record->entry->get('registerDate'); $eview->confirm = $this->record->entry->get('activation'); $eview->baseURL = Request::base(); $msg = new \Hubzero\Mail\Message(); $msg->setSubject(Config::get('sitename') . ' ' . Lang::txt('COM_MEMBERS_REGISTER_EMAIL_CONFIRMATION'))->addTo($this->record->entry->get('email'))->addFrom(Config::get('mailfrom'), Config::get('sitename') . ' Administrator')->addHeader('X-Component', 'com_members'); $message = $eview->loadTemplate(); $message = str_replace("\n", "\r\n", $message); $msg->addPart($message, 'text/plain'); $eview->setLayout('confirm_html'); $message = $eview->loadTemplate(); $message = str_replace("\n", "\r\n", $message); $msg->addPart($message, 'text/html'); if (!$msg->send()) { array_push($this->record->errors, Lang::txt('COM_MEMBERS_REGISTER_ERROR_EMAILING_CONFIRMATION')); } } }