Пример #1
0
 /**
  * Display a form for updating profile info
  *
  * @return  void
  */
 public function updateTask()
 {
     // Check if the user is logged in
     if (User::isGuest()) {
         return App::abort(500, Lang::txt('COM_MEMBERS_REGISTER_ERROR_SESSION_EXPIRED'));
     }
     $force = false;
     $updateEmail = false;
     // Set the pathway
     $this->_buildPathway();
     // Set the page title
     $this->_buildTitle();
     // Instantiate a new registration object
     $xregistration = new \Components\Members\Models\Registration();
     $xprofile = \Hubzero\User\Profile::getInstance(User::get('id'));
     $hzal = \Hubzero\Auth\Link::find_by_id(User::get('auth_link_id'));
     if (Request::getMethod() == 'POST') {
         // Load POSTed data
         $xregistration->loadPOST();
     } else {
         // Load data from the user object
         if (is_object($xprofile)) {
             $xregistration->loadProfile($xprofile);
         } else {
             $xregistration->loadAccount(User::getRoot());
         }
         $username = User::get('username');
         $email = User::get('email');
         if ($username[0] == '-' && is_object($hzal)) {
             $tmp_username = Session::get('auth_link.tmp_username', '');
             $xregistration->set('login', $tmp_username);
             $xregistration->set('orcid', Session::get('auth_link.tmp_orcid', ''));
             $xregistration->set('email', $hzal->email);
             $xregistration->set('confirmEmail', $hzal->email);
             $force = true;
         }
     }
     $check = $xregistration->check('update');
     if (!$force && $check && Request::getMethod() == 'GET') {
         Session::set('registration.incomplete', false);
         if ($_SERVER['REQUEST_URI'] == rtrim(Request::base(true), '/') . '/register/update' || $_SERVER['REQUEST_URI'] == rtrim(Request::base(true), '/') . '/members/register/update') {
             App::redirect(rtrim(Request::base(true), '/') . '/');
         } else {
             App::redirect($_SERVER['REQUEST_URI']);
         }
         return true;
     }
     if (!$force && $check && Request::getMethod() == 'POST') {
         // Before going any further, we need to do a sanity check to make sure username isn't being changed.
         // This really only happens on a race condition where someone is creating the same account
         // using a 3rd party auth service in two different browsers. Yes, it's crazy!
         if ($xregistration->get('login') && substr(User::get('username'), 0, 1) == '-') {
             // Make sure the username hasn't since been set in the database
             if (substr(User::getInstance(User::get('id'))->get('username'), 0, 1) != '-') {
                 App::redirect(Route::url('index.php?option=com_users&view=logout'), Lang::txt('This account appears to already exist. Please try logging in again.'), 'warning');
                 return;
             }
         }
         //$params = Component::params('com_members');
         $hubHomeDir = rtrim($this->config->get('homedir'), '/');
         $updateEmail = false;
         if ($xprofile->get('homeDirectory') == '') {
             $xprofile->set('homeDirectory', $hubHomeDir . '/' . $xprofile->get('username'));
         }
         if ($xprofile->get('regIP') == '') {
             $xprofile->set('regIP', Request::getVar('REMOTE_ADDR', '', 'server'));
         }
         if ($xprofile->get('regHost') == '') {
             if (isset($_SERVER['REMOTE_HOST'])) {
                 $xprofile->set('regHost', Request::getVar('REMOTE_HOST', '', 'server'));
             }
         }
         if ($xprofile->get('registerDate') == '') {
             $xprofile->set('registerDate', Date::toSql());
         }
         if ($xregistration->get('email') != $xprofile->get('email')) {
             if (is_object($hzal) && $xregistration->get('email') == $hzal->email) {
                 $xprofile->set('emailConfirmed', 3);
             } else {
                 $xprofile->set('emailConfirmed', -rand(1, pow(2, 31) - 1));
                 $updateEmail = true;
             }
         }
         if ($xregistration->get('login') != $xprofile->get('username')) {
             $xprofile->set('homeDirectory', $hubHomeDir . '/' . $xregistration->get('login'));
         }
         $xprofile->loadRegistration($xregistration);
         $xprofile->update();
         // Update user table
         // TODO: only update if changed
         $myuser = User::getInstance($xprofile->get('uidNumber'));
         $myuser->set('username', $xprofile->get('username'));
         $myuser->set('email', $xprofile->get('email'));
         $myuser->set('name', $xprofile->get('name'));
         $myuser->save();
         // Update current session if appropriate
         // TODO: update all session of this user
         // TODO: only update if changed
         if ($myuser->get('id') == User::get('id')) {
             $suser = Session::get('user');
             $suser->set('username', $xprofile->get('username'));
             $suser->set('email', $xprofile->get('email'));
             $suser->set('name', $xprofile->get('name'));
             Session::set('user', $suser);
             // Get the session object
             $table = \JTable::getInstance('session');
             $table->load(Session::getId());
             $table->username = $xprofile->get('username');
             $table->update();
         }
         Session::set('registration.incomplete', false);
         // Notify the user
         if ($updateEmail) {
             $subject = Config::get('sitename') . ' ' . Lang::txt('COM_MEMBERS_REGISTER_EMAIL_CONFIRMATION');
             $eview = new \Hubzero\Component\View(array('name' => 'emails', 'layout' => 'update'));
             $eview->option = $this->_option;
             $eview->controller = $this->_controller;
             $eview->sitename = Config::get('sitename');
             $eview->xprofile = $xprofile;
             $eview->baseURL = $this->baseURL;
             $message = $eview->loadTemplate();
             $message = str_replace("\n", "\r\n", $message);
             $msg = new \Hubzero\Mail\Message();
             $msg->setSubject($subject)->addTo($xprofile->get('email'))->addFrom(Config::get('mailfrom'), Config::get('sitename') . ' Administrator')->addHeader('X-Component', $this->_option)->setBody($message);
             if (!$msg->send()) {
                 $this->setError(Lang::txt('COM_MEMBERS_REGISTER_ERROR_EMAILING_CONFIRMATION'));
                 // @FIXME: LOG ERROR SOMEWHERE
             }
         }
         // Notify administration
         if (Request::getMethod() == 'POST') {
             $subject = Config::get('sitename') . ' ' . Lang::txt('COM_MEMBERS_REGISTER_EMAIL_ACCOUNT_UPDATE');
             $eaview = new \Hubzero\Component\View(array('name' => 'emails', 'layout' => 'adminupdate'));
             $eaview->option = $this->_option;
             $eaview->controller = $this->_controller;
             $eaview->sitename = Config::get('sitename');
             $eaview->xprofile = $xprofile;
             $eaview->baseURL = $this->baseURL;
             $message = $eaview->loadTemplate();
             $message = str_replace("\n", "\r\n", $message);
             /*$msg = new \Hubzero\Mail\Message();
             		$msg->setSubject($subject)
             		    ->addTo($hubMonitorEmail)
             		    ->addFrom(Config::get('mailfrom'), Config::get('sitename') . ' Administrator')
             		    ->addHeader('X-Component', $this->_option)
             		    ->setBody($message)
             		    ->send();*/
             // @FIXME: LOG ACCOUNT UPDATE ACTIVITY SOMEWHERE
         }
         if (!$updateEmail) {
             $suri = Request::getVar('REQUEST_URI', '/', 'server');
             if ($suri == '/register/update' || $suri == '/members/update') {
                 App::redirect(Route::url('index.php?option=' . $this->_option . '&task=myaccount'));
             } else {
                 App::redirect($suri);
             }
             return;
         } else {
             // Instantiate a new view
             $this->view->title = Lang::txt('COM_MEMBERS_REGISTER_UPDATE');
             $this->view->sitename = Config::get('sitename');
             $this->view->xprofile = $xprofile;
             $this->view->self = true;
             $this->view->updateEmail = $updateEmail;
             if ($this->getError()) {
                 $this->view->setError($this->getError());
             }
             $this->view->display();
         }
         return true;
     }
     return $this->_show_registration_form($xregistration, 'update');
 }
Пример #2
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();
 }