Пример #1
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;
 }
Пример #2
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');
 }
Пример #3
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 = Member::oneOrFail(User::get('id'));
     $hzal = \Hubzero\Auth\Link::find_by_id(User::get('auth_link_id'));
     // Get users component config options, specifically whether or not 'simple' registration is enabled
     $method = Request::getMethod();
     $usersConfig = Component::params('com_members');
     $simpleRegistration = $usersConfig->get('simple_registration', false);
     if ($method == 'POST') {
         // Load POSTed data
         $xregistration->loadPOST();
     } else {
         // Load data from the user object
         $xregistration->loadProfile($xprofile);
         $username = User::get('username');
         $email = User::get('email');
         if ($username[0] == '-' && is_object($hzal)) {
             $sub_email = explode('@', (string) $hzal->email, 2);
             $tmp_username = Session::get('auth_link.tmp_username', $sub_email[0]);
             $xregistration->set('login', $tmp_username);
             $xregistration->set('orcid', Session::get('auth_link.tmp_orcid', ''));
             $xregistration->set('email', $hzal->email);
             $xregistration->set('confirmEmail', $hzal->email);
             if ($simpleRegistration) {
                 $force = false;
                 $method = 'POST';
             } else {
                 $force = true;
             }
         }
     }
     $check = $xregistration->check('update');
     if (!$force && $check && $method == '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 && $method == '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;
             }
         }
         $hubHomeDir = rtrim($this->config->get('homedir'), DS);
         $updateEmail = false;
         if ($xprofile->get('homeDirectory') == '') {
             $xprofile->set('homeDirectory', $hubHomeDir . DS . $xprofile->get('username'));
         }
         if ($xprofile->get('registerIP') == '') {
             $xprofile->set('registerIP', Request::getVar('REMOTE_ADDR', '', '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('activation', 3);
             } else {
                 $code = \Components\Members\Helpers\Utility::genemailconfirm();
                 $xprofile->set('activation', $code);
                 $updateEmail = true;
             }
         }
         if ($xregistration->get('login') != $xprofile->get('username')) {
             $xprofile->set('homeDirectory', $hubHomeDir . DS . $xregistration->get('login'));
         }
         $keys = array('email', 'name', 'surname', 'givenName', 'middleName', 'usageAgreement', 'sendEmail', 'password');
         foreach ($keys as $key) {
             if ($xregistration->get($key) !== null) {
                 $xprofile->set($key, $xregistration->get($key));
             }
         }
         $xprofile->set('username', $xregistration->get('login'));
         $xprofile->save();
         // Update current session if appropriate
         // TODO: update all session of this user
         // TODO: only update if changed
         if ($xprofile->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) {
             \Components\Members\Helpers\Utility::sendConfirmEmail($xprofile, $xregistration);
         }
         // Notify administration
         if ($method == '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);
         }
         if (!$updateEmail) {
             $suri = Request::getVar('REQUEST_URI', '/', 'server');
             if ($suri == '/register/update' || $suri == '/members/update' || $suri == '/members/register/update') {
                 $suri = Route::url('index.php?option=' . $this->_option . '&task=myaccount');
             }
             App::redirect($suri);
             return;
         } else {
             // Instantiate a new view
             $this->view->set('title', Lang::txt('COM_MEMBERS_REGISTER_UPDATE'))->set('sitename', Config::get('sitename'))->set('xprofile', $xprofile)->set('isSelf', true)->set('updateEmail', $updateEmail)->setErrors($this->getErrors())->display();
         }
         return true;
     }
     return $this->_show_registration_form($xregistration, 'update');
 }
Пример #4
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();
 }
Пример #5
0
 /**
  * Event call to determine if this plugin should return data
  *
  * @param      array  $fields  Fields filled in
  * @param      object $profile MembersProfile
  * @return     integer
  */
 public function getProfileCompleteness($fields, $profile)
 {
     //default vars
     $num_fields = 0;
     $num_filled_fields = 0;
     $_property_map = array('Fullname' => 'name', 'Email' => 'email', 'URL' => 'web', 'Phone' => 'phone', 'Employment' => 'orgtype', 'Organization' => 'org', 'Citizenship' => 'countryorigin', 'Residency' => 'countryresident', 'Sex' => 'sex', 'Disability' => 'disability', 'Hispanic' => 'hispanic', 'Race' => 'race', 'Bio' => 'bio', 'Interests' => 'tags', 'OptIn' => 'mailPreferenceOption', 'ORCID' => 'orcid');
     //unset errors from the fields object
     $fields->setErrors(array());
     //load the user profile
     $registration = new \Components\Members\Models\Registration();
     $registration->loadProfile($profile);
     //add tags to the registration object
     $database = App::get('db');
     $mt = new \Components\Members\Models\Tags($profile->get('uidNumber'));
     $registration->_registration['tags'] = $mt->render('string');
     //add bio to the registration object
     $fields->Bio = REG_OPTIONAL;
     $registration->_registration['bio'] = $profile->get("bio");
     //loop through each field to see if we want to count it
     foreach ($fields as $k => $v) {
         //if the field is anything button hidden we want to count it
         if (in_array($v, array(REG_REQUIRED, REG_OPTIONAL, REG_READONLY))) {
             //check if we have a mapping (excludes certain unused vars)
             if (isset($_property_map[$k])) {
                 //add to the number of fields count
                 $num_fields++;
                 //check to see if we have it filled in
                 $value = $registration->get($_property_map[$k]);
                 $type = gettype($registration->get($_property_map[$k]));
                 if ($type == 'array' && !empty($value) || $type == 'string' && $value != '') {
                     $num_filled_fields++;
                 }
             }
         }
     }
     //return percentage
     return number_format($num_filled_fields / $num_fields * 100, 0);
 }
Пример #6
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;
 }