コード例 #1
0
ファイル: register.php プロジェクト: sumudinie/hubzero-cms
 /**
  * Conform user's registration code
  *
  * @return     void
  */
 public function confirmTask()
 {
     // Incoming
     $code = Request::getVar('confirm', false);
     if (!$code) {
         $code = Request::getVar('code', false);
     }
     // Check if the user is logged in
     if (User::isGuest()) {
         $return = base64_encode(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=' . $this->_task . '&confirm=' . $code, false, true));
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . $return, false), Lang::txt('Please login in so we can confirm your account.'), 'warning');
         return;
     }
     // Set the pathway
     $this->_buildPathway();
     // Set the page title
     $this->_buildTitle();
     $xprofile = \Hubzero\User\Profile::getInstance(User::get('id'));
     $email_confirmed = $xprofile->get('emailConfirmed');
     if ($email_confirmed == 1 || $email_confirmed == 3) {
         // The current user is confirmed - check to see if the incoming code is valid at all
         if (\Components\Members\Helpers\Utility::isActiveCode($code)) {
             $this->setError('login mismatch');
             // Build logout/login/confirm redirect flow
             $login_return = base64_encode(Route::url('index.php?option=' . $this->option . '&controller=' . $this->_controller . '&task=' . $this->_task . '&confirm=' . $code));
             $logout_return = base64_encode(Route::url('index.php?option=com_users&view=login&return=' . $login_return));
             $redirect = Route::url('index.php?option=com_users&view=logout&return=' . $logout_return);
         }
     } elseif ($email_confirmed < 0 && $email_confirmed == -$code) {
         //var to hold return path
         $return = '';
         // get return path
         $cReturn = $this->config->get('ConfirmationReturn');
         if ($cReturn) {
             $return = $cReturn;
         }
         //load user profile
         $profile = new \Hubzero\User\Profile();
         $profile->load($xprofile->get('username'));
         //check to see if we have a return param
         $pReturn = base64_decode(urldecode($profile->getParam('return')));
         if ($pReturn) {
             $return = $pReturn;
             $profile->setParam('return', '');
         }
         // make as confirmed
         $profile->set('emailConfirmed', 1);
         // set public setting
         $profile->set('public', $this->config->get('privacy', '0'));
         // upload profile
         if (!$profile->update()) {
             $this->setError(Lang::txt('COM_MEMBERS_REGISTER_ERROR_CONFIRMING'));
         }
         // if the user just changed their email & confirmed
         // reset 'userchangedemail' key
         if (Session::get('userchangedemail', 0) == 1) {
             Session::set('userchangedemail', 0);
         }
         // Redirect
         if (empty($return)) {
             $r = $this->config->get('ConfirmationReturn');
             $return = $r ? $r : Route::url('index.php?option=com_members&task=myaccount');
             // consume cookie (yum) if available to return to whatever action prompted registration
             if (isset($_COOKIE['return'])) {
                 $return = $_COOKIE['return'];
                 setcookie('return', '', time() - 3600);
             }
         }
         App::redirect($return, '', 'message', true);
     } else {
         $this->setError(Lang::txt('COM_MEMBERS_REGISTER_ERROR_INVALID_CONFIRMATION'));
     }
     // Instantiate a new view
     $this->view->title = Lang::txt('COM_MEMBERS_REGISTER_CONFIRM');
     $this->view->login = $xprofile->get('username');
     $this->view->email = $xprofile->get('email');
     $this->view->code = $code;
     $this->view->redirect = isset($return) ? $return : '';
     $this->view->sitename = Config::get('sitename');
     if ($this->getError()) {
         $this->view->setError($this->getError());
     }
     $this->view->display();
 }