Esempio n. 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');
 }
Esempio n. 2
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);
 }
Esempio n. 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');
 }