Пример #1
0
 /**
  * Method to validate the form data.
  *
  * @param   JForm   $form   The form to validate against.
  * @param   array   $data   The data to validate.
  * @param   string  $group  The name of the field group to validate.
  *
  * @return  mixed  Array of filtered data if valid, false otherwise.
  */
 public function validate($form, $data, $group = null)
 {
     // Fire HUBzero registration check here so that we don't have to duplicate validation code
     require_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'models' . DS . 'registration.php';
     $registration = new \Components\Members\Models\Registration();
     $registration->set('name', $data['name']);
     $registration->set('login', $data['username']);
     $registration->set('email', $data['email']);
     $registration->set('confirmEmail', $data['email']);
     if (!$registration->check('create', $data['id'], array('name', 'login', 'email'))) {
         $this->setError(implode("<br/>", $registration->_invalid));
         return false;
     }
     return parent::validate($form, $data, $group);
 }
Пример #2
0
 /**
  * Short description for 'create'
  *
  * Long description (if any) ...
  *
  * @return     mixed Return description (if any) ...
  */
 public function createTask()
 {
     if (!User::isGuest() && !User::get('tmp_user')) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&task=myaccount'), Lang::txt('COM_MEMBERS_REGISTER_ERROR_NONGUEST_SESSION_CREATION'), 'warning');
         return;
     }
     if (!isset($this->_taskMap[$this->_task])) {
         $this->_task = 'create';
         Request::setVar('task', 'create');
     }
     // Set the pathway
     $this->_buildPathway();
     // Set the page title
     $this->_buildTitle();
     $usersConfig = Component::params('com_users');
     if ($usersConfig->get('allowUserRegistration') == '0') {
         return App::abort(404, Lang::txt('JGLOBAL_RESOURCE_NOT_FOUND'));
     }
     $hzal = null;
     if (User::get('auth_link_id')) {
         $hzal = \Hubzero\Auth\Link::find_by_id(User::get('auth_link_id'));
     }
     // Instantiate a new registration object
     $xregistration = new \Components\Members\Models\Registration();
     if (Request::getMethod() == 'POST') {
         // Check for request forgeries
         Request::checkToken();
         // Load POSTed data
         $xregistration->loadPost();
         // Perform field validation
         if ($xregistration->check('create')) {
             // Get required system objects
             $user = clone User::getRoot();
             $authorize = \JFactory::getACL();
             // If user registration is not allowed, show 403 not authorized.
             if ($usersConfig->get('allowUserRegistration') == '0') {
                 App::abort(403, Lang::txt('Access Forbidden'));
                 return;
             }
             // Initialize new usertype setting
             $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->set('username', $xregistration->get('login'));
             $user->set('name', $xregistration->get('name'));
             $user->set('email', $xregistration->get('email'));
             /*
             // Bind the post array to the user object
             if (!$user->bind(Request::get('post'), 'usertype')) {
             	App::abort(500, $user->getError());
             }
             */
             // Set some initial user values
             $user->set('id', 0);
             $user->set('groups', array($newUsertype));
             $date = Date::of('now');
             $user->set('registerDate', $date->toSql());
             // Check user activation setting
             // 0 = automatically confirmed
             // 1 = require email confirmation (the norm)
             // 2 = require admin confirmation
             $useractivation = $usersConfig->get('useractivation', 1);
             // If requiring admin approval, set user to block
             if ($useractivation == 2) {
                 $user->set('approved', 0);
             }
             // If there was an error with registration, set the message and display form
             if ($user->save()) {
                 /*
                 // Send registration confirmation mail
                 $password = Request::getString('password', '', 'post', JREQUEST_ALLOWRAW);
                 $password = preg_replace('/[\x00-\x1F\x7F]/', '', $password); //Disallow control chars in the email
                 UserController::_sendMail($user, $password);
                 
                 // Everything went fine, set relevant message depending upon user activation state and display message
                 if ($useractivation == 1)
                 {
                 	$message  = Lang::txt('REG_COMPLETE_ACTIVATE');
                 }
                 else
                 {
                 	$message = Lang::txt('REG_COMPLETE');
                 }
                 
                 App::redirect(Route::url('index.php'), $message);
                 */
                 // Get some settings
                 $params = Component::params('com_members');
                 $hubHomeDir = rtrim($params->get('homedir'), '/');
                 // Attempt to get the new user
                 $xprofile = \Hubzero\User\Profile::getInstance($user->get('id'));
                 $result = is_object($xprofile);
                 // Did we successfully create an account?
                 if ($result) {
                     $xprofile->loadRegistration($xregistration);
                     if (is_object($hzal)) {
                         if ($xprofile->get('email') == $hzal->email) {
                             $xprofile->set('emailConfirmed', 3);
                         } else {
                             $xprofile->set('emailConfirmed', -rand(1, pow(2, 31) - 1));
                         }
                     } else {
                         if ($useractivation == 0) {
                             $xprofile->set('emailConfirmed', 1);
                         }
                     }
                     $xprofile->set('public', 0);
                     // Do we have a return URL?
                     $regReturn = Request::getVar('return', '');
                     if ($regReturn) {
                         $xprofile->setParam('return', $regReturn);
                     }
                     // Unset password here so that change password below can be in charge of setting it initially
                     $xprofile->set('password', '');
                     $result = $xprofile->update();
                 }
                 // add member interests
                 $interests = $xregistration->get('interests');
                 $mt = new \Components\Members\Models\Tags($xprofile->get('uidNumber'));
                 if (!empty($interests)) {
                     $mt->setTags($interests, $xprofile->get('uidNumber'));
                 }
                 if ($result) {
                     $result = \Hubzero\User\Password::changePassword($xprofile->get('uidNumber'), $xregistration->get('password'));
                     // Set password back here in case anything else down the line is looking for it
                     $xprofile->set('password', $xregistration->get('password'));
                 }
                 // Did we successfully create/update an account?
                 if (!$result) {
                     return App::abort(500, Lang::txt('COM_MEMBERS_REGISTER_ERROR_CREATING_ACCOUNT'));
                 }
                 if ($xprofile->get('emailConfirmed') < 0) {
                     // Notify the user
                     $subject = Config::get('sitename') . ' ' . Lang::txt('COM_MEMBERS_REGISTER_EMAIL_CONFIRMATION');
                     $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'create'));
                     $eview->option = $this->_option;
                     $eview->controller = $this->_controller;
                     $eview->sitename = Config::get('sitename');
                     $eview->xprofile = $xprofile;
                     $eview->baseURL = $this->baseURL;
                     $eview->xregistration = $xregistration;
                     $msg = new \Hubzero\Mail\Message();
                     $msg->setSubject($subject)->addTo($xprofile->get('email'), $xprofile->get('name'))->addFrom(Config::get('mailfrom'), Config::get('sitename') . ' Administrator')->addHeader('X-Component', $this->_option);
                     $message = $eview->loadTemplate(false);
                     $message = str_replace("\n", "\r\n", $message);
                     $msg->addPart($message, 'text/plain');
                     $eview->setLayout('create_html');
                     $message = $eview->loadTemplate();
                     $message = str_replace("\n", "\r\n", $message);
                     $msg->addPart($message, 'text/html');
                     if (!$msg->send()) {
                         $this->setError(Lang::txt('COM_MEMBERS_REGISTER_ERROR_EMAILING_CONFIRMATION'));
                         // @FIXME: LOG ERROR SOMEWHERE
                     }
                 }
                 // Notify administration
                 if ($usersConfig->get('mail_to_admin', 0)) {
                     $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'admincreate_plain'));
                     $eview->option = $this->_option;
                     $eview->controller = $this->_controller;
                     $eview->sitename = Config::get('sitename');
                     $eview->xprofile = $xprofile;
                     $eview->baseUrl = $this->baseURL;
                     $plain = $eview->loadTemplate(false);
                     $plain = str_replace("\n", "\r\n", $plain);
                     // HTML
                     $eview->setLayout('admincreate_html');
                     $html = $eview->loadTemplate();
                     $html = str_replace("\n", "\r\n", $html);
                     $hubMonitorEmail = Config::get('mailfrom');
                     $message = new \Hubzero\Mail\Message();
                     $message->setSubject(Config::get('sitename') . ' ' . Lang::txt('COM_MEMBERS_REGISTER_EMAIL_ACCOUNT_CREATION'))->addTo($hubMonitorEmail)->addFrom(Config::get('mailfrom'), Config::get('sitename') . ' Administrator')->addHeader('X-Component', $this->_option)->addHeader('X-Component-Object', 'user_creation_admin_notification')->addPart($plain, 'text/plain')->addPart($html, 'text/html');
                     // Send mail
                     if (!$message->send()) {
                         \Log::error('Members admin notification email failed: ' . Lang::txt('Failed to mail %s', $hubMonitorEmail));
                     }
                 }
                 // Instantiate a new view
                 $this->view->setLayout('create');
                 $this->view->title = Lang::txt('COM_MEMBERS_REGISTER_CREATE_ACCOUNT');
                 $this->view->sitename = Config::get('sitename');
                 $this->view->xprofile = $xprofile;
                 if ($this->getError()) {
                     $this->view->setError($this->getError());
                 }
                 $this->view->display();
                 if (is_object($hzal)) {
                     $hzal->user_id = $user->get('id');
                     if ($hzal->user_id > 0) {
                         $hzal->update();
                     }
                 }
                 User::set('auth_link_id', null);
                 User::set('tmp_user', null);
                 User::set('username', $xregistration->get('login'));
                 User::set('email', $xregistration->get('email'));
                 User::set('id', $user->get('id'));
                 return;
             }
         }
     }
     if (Request::method() == 'GET') {
         if (User::get('tmp_user')) {
             $xregistration->loadAccount(User::getRoot());
             $username = $xregistration->get('login');
             $email = $xregistration->get('email');
             if (is_object($hzal)) {
                 $xregistration->set('login', $hzal->username);
                 $xregistration->set('email', $hzal->email);
                 $xregistration->set('confirmEmail', $hzal->email);
             }
         }
     }
     return $this->_show_registration_form($xregistration, 'create');
 }
Пример #3
0
 /**
  * Check Data integrity
  *
  * @return  $this  Current object
  */
 public function check()
 {
     // Run save check method
     if (!$this->record->entry->check()) {
         array_push($this->record->errors, $this->record->entry->getError());
         return $this;
     }
     $xregistration = new \Components\Members\Models\Registration();
     $xregistration->loadProfile($this->_profile);
     // Check that required fields were filled in properly
     if (!$xregistration->check('edit', $this->_profile->get('uidNumber'), array())) {
         if (!empty($xregistration->_missing)) {
             foreach ($xregistration->_missing as $missing) {
                 array_push($this->record->errors, $missing);
             }
         }
         if (!empty($xregistration->_invalid)) {
             foreach ($xregistration->_invalid as $invalid) {
                 array_push($this->record->errors, $invalid);
             }
         }
     }
     return $this;
 }
Пример #4
0
 /**
  * Show a form for registering
  *
  * @return  void
  */
 public function createTask()
 {
     if (!User::isGuest() && !User::get('tmp_user')) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&task=myaccount'), Lang::txt('COM_MEMBERS_REGISTER_ERROR_NONGUEST_SESSION_CREATION'), 'warning');
     }
     if (!isset($this->_taskMap[$this->_task])) {
         $this->_task = 'create';
         Request::setVar('task', 'create');
     }
     // If user registration is not allowed, show 403 not authorized.
     $usersConfig = Component::params('com_members');
     if ($usersConfig->get('allowUserRegistration') == '0') {
         return App::abort(404, Lang::txt('JGLOBAL_RESOURCE_NOT_FOUND'));
     }
     $hzal = null;
     if (User::get('auth_link_id')) {
         $hzal = \Hubzero\Auth\Link::find_by_id(User::get('auth_link_id'));
     }
     // Instantiate a new registration object
     $xregistration = new \Components\Members\Models\Registration();
     if (Request::getMethod() == 'POST') {
         // Check for request forgeries
         Request::checkToken();
         // Load POSTed data
         $xregistration->loadPost();
         // Perform field validation
         $result = $xregistration->check('create');
         // Incoming profile edits
         $profile = Request::getVar('profile', array(), 'post', 'none', 2);
         // Compile profile data
         foreach ($profile as $key => $data) {
             if (isset($profile[$key]) && is_array($profile[$key])) {
                 $profile[$key] = array_filter($profile[$key]);
             }
             if (isset($profile[$key . '_other']) && trim($profile[$key . '_other'])) {
                 if (is_array($profile[$key])) {
                     $profile[$key][] = $profile[$key . '_other'];
                 } else {
                     $profile[$key] = $profile[$key . '_other'];
                 }
                 unset($profile[$key . '_other']);
             }
         }
         // Validate profile data
         $fields = \Components\Members\Models\Profile\Field::all()->including(['options', function ($option) {
             $option->select('*');
         }])->where('action_create', '!=', \Components\Members\Models\Profile\Field::STATE_HIDDEN)->ordered()->rows();
         // Validate profile fields
         if ($fields->count()) {
             $form = new \Hubzero\Form\Form('profile', array('control' => 'profile'));
             $form->load(\Components\Members\Models\Profile\Field::toXml($fields, 'create', $profile));
             $form->bind(new \Hubzero\Config\Registry($profile));
             if (!$form->validate($profile)) {
                 $result = false;
                 foreach ($form->getErrors() as $key => $error) {
                     if ($error instanceof \Hubzero\Form\Exception\MissingData) {
                         $xregistration->_missing[$key] = $error;
                     }
                     $xregistration->_invalid[$key] = $error;
                 }
             }
         }
         // Passed validation?
         if ($result) {
             // Get required system objects
             $user = clone User::getInstance();
             // Initialize new usertype setting
             $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->set('username', $xregistration->get('login', ''));
             $user->set('name', $xregistration->get('name', ''));
             $user->set('givenName', $xregistration->get('givenName', ''));
             $user->set('middleName', $xregistration->get('middleName', ''));
             $user->set('surname', $xregistration->get('surname', ''));
             $user->set('email', $xregistration->get('email', ''));
             $user->set('usageAgreement', (int) $xregistration->get('usageAgreement', 0));
             $user->set('sendEmail', -1);
             if ($xregistration->get('sendEmail') >= 0) {
                 $user->set('sendEmail', (int) $xregistration->get('sendEmail'));
             }
             // Set home directory
             $hubHomeDir = rtrim($this->config->get('homedir'), '/');
             if (!$hubHomeDir) {
                 // try to deduce a viable home directory based on sitename or live_site
                 $sitename = strtolower(Config::get('sitename'));
                 $sitename = preg_replace('/^http[s]{0,1}:\\/\\//', '', $sitename, 1);
                 $sitename = trim($sitename, '/ ');
                 $sitename_e = explode('.', $sitename, 2);
                 if (isset($sitename_e[1])) {
                     $sitename = $sitename_e[0];
                 }
                 if (!preg_match("/^[a-zA-Z]+[\\-_0-9a-zA-Z\\.]+\$/i", $sitename)) {
                     $sitename = '';
                 }
                 if (empty($sitename)) {
                     $sitename = strtolower(Request::base());
                     $sitename = preg_replace('/^http[s]{0,1}:\\/\\//', '', $sitename, 1);
                     $sitename = trim($sitename, '/ ');
                     $sitename_e = explode('.', $sitename, 2);
                     if (isset($sitename_e[1])) {
                         $sitename = $sitename_e[0];
                     }
                     if (!preg_match("/^[a-zA-Z]+[\\-_0-9a-zA-Z\\.]+\$/i", $sitename)) {
                         $sitename = '';
                     }
                 }
                 $hubHomeDir = DS . 'home';
                 if (!empty($sitename)) {
                     $hubHomeDir .= DS . $sitename;
                 }
             }
             $user->set('homeDirectory', $hubHomeDir . DS . $user->get('username'));
             $user->set('loginShell', '/bin/bash');
             $user->set('ftpShell', '/usr/lib/sftp-server');
             // Set some initial user values
             $user->set('id', 0);
             $user->set('accessgroups', array($newUsertype));
             $user->set('registerDate', Date::toSql());
             // Check user activation setting
             // 0 = automatically confirmed
             // 1 = require email confirmation (the norm)
             // 2 = require admin confirmation
             $useractivation = $usersConfig->get('useractivation', 1);
             // If requiring admin approval, set user to block
             if ($useractivation == 2) {
                 $user->set('approved', 0);
             }
             $user->set('access', 5);
             $user->set('activation', -rand(1, pow(2, 31) - 1));
             if (is_object($hzal)) {
                 if ($user->get('email') == $hzal->email) {
                     $user->set('activation', 3);
                 }
             } else {
                 if ($useractivation == 0) {
                     $user->set('activation', 1);
                     $user->set('access', (int) $this->config->get('privacy', 1));
                 }
             }
             $user->set('password', \Hubzero\User\Password::getPasshash($xregistration->get('password')));
             // Do we have a return URL?
             $regReturn = Request::getVar('return', '');
             if ($regReturn) {
                 $user->setParam('return', $regReturn);
             }
             // If we managed to create a user
             if ($user->save()) {
                 $access = array();
                 foreach ($fields as $field) {
                     $access[$field->get('name')] = $field->get('access');
                 }
                 $profile = $xregistration->_registration['_profile'];
                 // Save profile data
                 $member = Member::oneOrNew($user->get('id'));
                 if (!$member->saveProfile($profile, $access)) {
                     \Notify::error($member->getError());
                     // Don't stop the registration process!
                     // At this point, the account was successfully created.
                     // The profile info, however, may have issues. But, it's not crucial.
                     //$result = false;
                 }
             } else {
                 \Notify::error($user->getError());
                 $result = false;
             }
             // If everything is OK so far...
             if ($result) {
                 $result = \Hubzero\User\Password::changePassword($user->get('id'), $xregistration->get('password'));
                 // Set password back here in case anything else down the line is looking for it
                 $user->set('password', $xregistration->get('password'));
                 // Did we successfully create/update an account?
                 if (!$result) {
                     return App::abort(500, Lang::txt('COM_MEMBERS_REGISTER_ERROR_CREATING_ACCOUNT'));
                 }
                 // Send confirmation email
                 if ($user->get('activation') < 0) {
                     \Components\Members\Helpers\Utility::sendConfirmEmail($user, $xregistration);
                 }
                 // Instantiate a new view
                 $this->view->set('title', Lang::txt('COM_MEMBERS_REGISTER_CREATE_ACCOUNT'))->set('sitename', Config::get('sitename'))->set('xprofile', $user)->setErrors($this->getErrors())->setLayout('create')->display();
                 if (is_object($hzal)) {
                     $hzal->user_id = $user->get('id');
                     if ($hzal->user_id > 0) {
                         $hzal->update();
                     }
                 }
                 User::set('auth_link_id', null);
                 User::set('tmp_user', null);
                 User::set('username', $xregistration->get('login'));
                 User::set('email', $xregistration->get('email'));
                 User::set('id', $user->get('id'));
                 return;
             }
         }
     }
     if (Request::method() == 'GET') {
         if (User::get('tmp_user')) {
             $xregistration->loadAccount(User::getInstance());
             $username = $xregistration->get('login');
             $email = $xregistration->get('email');
             if (is_object($hzal)) {
                 $xregistration->set('login', $hzal->username);
                 $xregistration->set('email', $hzal->email);
                 $xregistration->set('confirmEmail', $hzal->email);
             }
         }
     }
     // Set the pathway
     $this->_buildPathway();
     // Set the page title
     $this->_buildTitle();
     return $this->_show_registration_form($xregistration, 'create');
 }
Пример #5
0
 /**
  * View the profile page
  *
  * @return  string
  */
 private function display()
 {
     //get member params
     $rparams = new \Hubzero\Config\Registry($this->member->get('params'));
     //get profile plugin's params
     $params = $this->params;
     $params->merge($rparams);
     $xreg = null;
     $fields = Components\Members\Models\Profile\Field::all()->including(['options', function ($option) {
         $option->select('*')->ordered();
     }])->where('action_edit', '!=', Components\Members\Models\Profile\Field::STATE_HIDDEN)->ordered()->rows();
     if (App::get('session')->get('registration.incomplete')) {
         $xreg = new \Components\Members\Models\Registration();
         $xreg->loadProfile($this->member);
         $check = $xreg->check('update');
         // Validate profile data
         // @TODO  Move this to central validation model (e.g., registraiton)?
         // Compile profile data
         $profile = array();
         foreach ($fields as $field) {
             $profile[$field->get('name')] = $this->member->get($field->get('name'));
         }
         // Validate profile fields
         $form = new Hubzero\Form\Form('profile', array('control' => 'profile'));
         $form->load(Components\Members\Models\Profile\Field::toXml($fields, 'edit', $profile));
         $form->bind(new Hubzero\Config\Registry($profile));
         if (!$form->validate($profile)) {
             $check = false;
             foreach ($form->getErrors() as $key => $error) {
                 if ($error instanceof Hubzero\Form\Exception\MissingData) {
                     $xreg->_missing[$key] = (string) $error;
                 }
                 $xreg->_invalid[$key] = (string) $error;
             }
         }
         // If no errors, redirect to where they were going
         if ($check) {
             App::get('session')->set('registration.incomplete', 0);
             App::redirect($_SERVER['REQUEST_URI']);
         }
     }
     $view = $this->view('default', 'index')->set('params', $params)->set('option', 'com_members')->set('profile', $this->member)->set('fields', $fields)->set('completeness', $this->getProfileCompleteness($fields, $this->member))->set('registration_update', $xreg);
     return $view->setErrors($this->getErrors())->loadTemplate();
 }
Пример #6
0
 /**
  * View the profile page
  *
  * @return     string
  */
 private function display()
 {
     // Find out which fields are hidden, optional, or required
     $registration = new \Hubzero\Base\Object();
     $registration->Fullname = $this->_registrationField('registrationFullname', 'RRRR', 'edit');
     $registration->Email = $this->_registrationField('registrationEmail', 'RRRR', 'edit');
     $registration->URL = $this->_registrationField('registrationURL', 'HHHH', 'edit');
     $registration->Phone = $this->_registrationField('registrationPhone', 'HHHH', 'edit');
     $registration->Employment = $this->_registrationField('registrationEmployment', 'HHHH', 'edit');
     $registration->Organization = $this->_registrationField('registrationOrganization', 'HHHH', 'edit');
     $registration->Citizenship = $this->_registrationField('registrationCitizenship', 'HHHH', 'edit');
     $registration->Residency = $this->_registrationField('registrationResidency', 'HHHH', 'edit');
     $registration->Sex = $this->_registrationField('registrationSex', 'HHHH', 'edit');
     $registration->Disability = $this->_registrationField('registrationDisability', 'HHHH', 'edit');
     $registration->Hispanic = $this->_registrationField('registrationHispanic', 'HHHH', 'edit');
     $registration->Race = $this->_registrationField('registrationRace', 'HHHH', 'edit');
     $registration->Interests = $this->_registrationField('registrationInterests', 'HHHH', 'edit');
     $registration->Reason = $this->_registrationField('registrationReason', 'HHHH', 'edit');
     $registration->OptIn = $this->_registrationField('registrationOptIn', 'HHHH', 'edit');
     $registration->address = $this->_registrationField('registrationAddress', 'OOOO', 'edit');
     $registration->ORCID = $this->_registrationField('registrationORCID', 'OOOO', 'edit');
     //get member params
     $rparams = new \Hubzero\Config\Registry($this->member->get('params'));
     //get profile plugin's params
     $params = $this->params;
     $params->merge($rparams);
     $this->view = $this->view('default', 'index');
     $registration_update = null;
     if (App::get('session')->get('registration.incomplete')) {
         $xreg = new \Components\Members\Models\Registration();
         $xprofile = \Hubzero\User\Profile::getInstance(User::get('id'));
         if (is_object($xprofile)) {
             $xreg->loadProfile($xprofile);
         } else {
             $xreg->loadAccount(User::getRoot());
         }
         $check = $xreg->check('update');
         if ($check) {
             App::get('session')->set('registration.incomplete', 0);
             App::redirect($_SERVER['REQUEST_URI']);
         } else {
             $registration_update = $xreg;
         }
     }
     //get profile completeness
     $this->view->completeness = $this->getProfileCompleteness($registration, $this->member);
     $this->view->option = 'com_members';
     $this->view->profile = $this->member;
     $this->view->registration = $registration;
     $this->view->registration_update = $registration_update;
     $this->view->params = $params;
     if ($this->getError()) {
         $this->view->setError($this->getError());
     }
     return $this->view->loadTemplate();
 }
Пример #7
0
 /**
  * Check Data integrity
  *
  * @return  $this  Current object
  */
 public function check()
 {
     // Run save check method
     /*if (!$this->record->entry->check())
     		{
     			array_push($this->record->errors, $this->record->entry->getError());
     			return $this;
     		}*/
     $xregistration = new \Components\Members\Models\Registration();
     $xregistration->loadProfile($this->record->entry);
     // Check that required fields were filled in properly
     if (!$xregistration->check('edit', $this->record->entry->get('id'), array())) {
         $skip = array();
         if (!empty($xregistration->_missing)) {
             foreach ($xregistration->_missing as $key => $missing) {
                 if ($this->_mode == 'PATCH') {
                     $skip[] = $key;
                     continue;
                 }
                 array_push($this->record->errors, $missing);
             }
         }
         if (!empty($xregistration->_invalid)) {
             foreach ($xregistration->_invalid as $key => $invalid) {
                 if (in_array($key, $skip)) {
                     continue;
                 }
                 array_push($this->record->errors, $invalid);
             }
         }
     }
     // Validate profile data
     $fields = \Components\Members\Models\Profile\Field::all()->including(['options', function ($option) {
         $option->select('*');
     }])->where('action_edit', '!=', \Components\Members\Models\Profile\Field::STATE_HIDDEN)->ordered()->rows();
     $form = new \Hubzero\Form\Form('profile', array('control' => 'profile'));
     $form->load(\Components\Members\Models\Profile\Field::toXml($fields, 'edit'));
     $form->bind(new \Hubzero\Config\Registry($this->_profile));
     if (!$form->validate($this->_profile)) {
         foreach ($form->getErrors() as $key => $error) {
             array_push($this->record->errors, (string) $error);
         }
     }
     return $this;
 }
Пример #8
0
 /**
  * Save changes to a profile
  * Outputs JSON when called via AJAX, redirects to profile otherwise
  *
  * @return     string JSON
  */
 public function saveTask()
 {
     // Check if they are logged in
     if (User::isGuest()) {
         return false;
     }
     Request::checkToken(array('get', 'post'));
     $no_html = Request::getVar("no_html", 0);
     // Incoming user ID
     $id = Request::getInt('id', 0, 'post');
     // Do we have an ID?
     if (!$id) {
         App::abort(404, Lang::txt('MEMBERS_NO_ID'));
         return;
     }
     // Incoming profile edits
     $p = Request::getVar('profile', array(), 'post', 'none', 2);
     $n = Request::getVar('name', array(), 'post');
     $a = Request::getVar('access', array(), 'post');
     // Load the profile
     $profile = \Hubzero\User\Profile::getInstance($id);
     $oldemail = $profile->get('email');
     if ($n) {
         $profile->set('givenName', trim($n['first']));
         $profile->set('middleName', trim($n['middle']));
         $profile->set('surname', trim($n['last']));
         $name = trim($n['first']) . ' ';
         $name .= trim($n['middle']) != '' ? trim($n['middle']) . ' ' : '';
         $name .= trim($n['last']);
         $profile->set('name', $name);
     }
     if (isset($p['bio'])) {
         $profile->set('bio', trim($p['bio']));
     }
     if (is_array($a) && count($a) > 0) {
         foreach ($a as $k => $v) {
             $v = intval($v);
             if (!in_array($v, array(0, 1, 2, 3, 4))) {
                 $v = 0;
             }
             $profile->setParam('access_' . $k, $v);
         }
     }
     if (isset($p['public'])) {
         $profile->set('public', $p['public']);
     }
     // Set some post data for the xregistration class
     $tags = trim(Request::getVar('tags', ''));
     if (isset($tags)) {
         Request::setVar('interests', $tags, 'post');
     }
     // Instantiate a new \Components\Members\Models\Registration
     $xregistration = new \Components\Members\Models\Registration();
     $xregistration->loadPOST();
     // Push the posted data to the profile
     // Note: this is done before the required fields check so, if we need to display the edit form, it'll show all the new changes
     if (!is_null($xregistration->_registration['email'])) {
         $profile->set('email', $xregistration->_registration['email']);
         // Unconfirm if the email address changed
         if ($oldemail != $xregistration->_registration['email']) {
             // Get a new confirmation code
             $confirm = \Components\Members\Helpers\Utility::genemailconfirm();
             $profile->set('emailConfirmed', $confirm);
         }
     }
     if (!is_null($xregistration->_registration['countryresident'])) {
         $profile->set('countryresident', $xregistration->_registration['countryresident']);
     }
     if (!is_null($xregistration->_registration['countryorigin'])) {
         $profile->set('countryorigin', $xregistration->_registration['countryorigin']);
     }
     if (!is_null($xregistration->_registration['nativetribe'])) {
         $profile->set('nativeTribe', $xregistration->_registration['nativetribe']);
     }
     if ($xregistration->_registration['org'] != '') {
         $profile->set('organization', $xregistration->_registration['org']);
     } elseif ($xregistration->_registration['orgtext'] != '') {
         $profile->set('organization', $xregistration->_registration['orgtext']);
     }
     if (!is_null($xregistration->_registration['web'])) {
         $profile->set('url', $xregistration->_registration['web']);
     }
     if (!is_null($xregistration->_registration['phone'])) {
         $profile->set('phone', $xregistration->_registration['phone']);
     }
     if (!is_null($xregistration->_registration['orgtype'])) {
         $profile->set('orgtype', $xregistration->_registration['orgtype']);
     }
     if (!is_null($xregistration->_registration['sex'])) {
         $profile->set('gender', $xregistration->_registration['sex']);
     }
     if (!is_null($xregistration->_registration['disability'])) {
         $profile->set('disability', $xregistration->_registration['disability']);
     }
     if (!is_null($xregistration->_registration['hispanic'])) {
         $profile->set('hispanic', $xregistration->_registration['hispanic']);
     }
     if (!is_null($xregistration->_registration['race'])) {
         $profile->set('race', $xregistration->_registration['race']);
     }
     if (!is_null($xregistration->_registration['mailPreferenceOption'])) {
         $profile->set('mailPreferenceOption', $xregistration->_registration['mailPreferenceOption']);
     }
     if (!is_null($xregistration->_registration['usageAgreement'])) {
         $profile->set('usageAgreement', $xregistration->_registration['usageAgreement']);
     }
     if (!is_null($xregistration->_registration['orcid'])) {
         $profile->set('orcid', $xregistration->_registration['orcid']);
     }
     $field_to_check = Request::getVar("field_to_check", array());
     // Check that required fields were filled in properly
     if (!$xregistration->check('edit', $profile->get('uidNumber'), $field_to_check)) {
         if (!$no_html) {
             $this->_task = 'edit';
             $this->editTask($xregistration, $profile);
             return;
         } else {
             echo json_encode($xregistration);
             exit;
         }
     }
     //are we declining the terms of use
     //if yes we want to set the usage agreement to 0 and profile to private
     $declineTOU = Request::getVar('declinetou', 0);
     if ($declineTOU) {
         $profile->set('public', 0);
         $profile->set('usageAgreement', 0);
     }
     // Set the last modified datetime
     $profile->set('modifiedDate', Date::toSql());
     // Save the changes
     if (!$profile->update()) {
         App::abort(500, $profile->getError());
         return false;
     }
     // Process tags
     if (isset($tags) && in_array('interests', $field_to_check)) {
         $mt = new \Components\Members\Models\Tags($id);
         $mt->setTags($tags, $id);
     }
     $email = $profile->get('email');
     $name = $profile->get('name');
     // Make sure certain changes make it back to the user table
     if ($id > 0) {
         $user = User::getInstance($id);
         $jname = $user->get('name');
         $jemail = $user->get('email');
         if ($name != trim($jname)) {
             $user->set('name', $name);
         }
         if ($email != trim($jemail)) {
             $user->set('email', $email);
         }
         if ($name != trim($jname) || $email != trim($jemail)) {
             if (!$user->save()) {
                 App::abort(500, Lang::txt($user->getError()));
                 return false;
             }
         }
         // Update session if name is changing
         if ($n && $user->get('name') != App::get('session')->get('user')->get('name')) {
             $suser = App::get('session')->get('user');
             $user->set('name', $suser->get('name'));
         }
         // Update session if email is changing
         if ($user->get('email') != App::get('session')->get('user')->get('email')) {
             $suser = App::get('session')->get('user');
             $user->set('email', $suser->get('email'));
             // add item to session to mark that the user changed emails
             // this way we can serve profile images for these users but not all
             // unconfirmed users
             $session = App::get('session');
             $session->set('userchangedemail', 1);
         }
     }
     // Send a new confirmation code AFTER we've successfully saved the changes to the e-mail address
     if ($email != $oldemail) {
         $this->_message = $this->_sendConfirmationCode($profile->get('username'), $email, $confirm);
     }
     //if were declinging the terms we want to logout user and tell the javascript
     if ($declineTOU) {
         App::get('auth')->logout();
         echo json_encode(array('loggedout' => true));
         return;
     }
     if (!$no_html) {
         // Redirect
         App::redirect(Route::url('index.php?option=' . $this->_option . ($id ? '&id=' . $id . '&active=profile' : '')), $this->_message);
     } else {
         // Output JSON
         echo json_encode(array('success' => true));
     }
 }