Exemple #1
0
 /**
  * Step 2: Save register information
  * @return boolean
  */
 public function register_save()
 {
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     $modelRegister = CFactory::getModel('register');
     // Check for request forgeries
     $mySess = JFactory::getSession();
     if (!$mySess->has('JS_REG_TOKEN')) {
         echo '<div class="error-box">' . JText::_('COM_COMMUNITY_INVALID_SESSION') . '</div>';
         return;
     }
     $token = $mySess->get('JS_REG_TOKEN', '');
     $ipAddress = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
     $authKey = $modelRegister->getAssignedAuthKey($token, $ipAddress);
     $formToken = $jinput->request->get('authkey', '', 'STRING');
     if (empty($formToken) || empty($authKey) || $formToken != $authKey) {
         echo '<div class="error-box">' . JText::_('COM_COMMUNITY_INVALID_TOKEN') . '</div>';
         return;
     }
     //update the auth key life span to another 180 sec.
     $modelRegister->updateAuthKey($token, $authKey, $ipAddress);
     // Get required system objects
     $config = CFactory::getConfig();
     $post = JRequest::get('post');
     // If user registration is not allowed, show 403 not authorized.
     $usersConfig = JComponentHelper::getParams('com_users');
     /* Do not allow for user registration */
     if ($usersConfig->get('allowUserRegistration') == '0') {
         //show warning message
         $view = $this->getView('register');
         $view->addWarning(JText::_('COM_COMMUNITY_REGISTRATION_DISABLED'));
         echo $view->get('register');
         return;
     }
     //perform forms validation before continue further.
     /*
      * Rules:
      * First we let 3rd party plugin to intercept the validation.
      * if there is not error return, we then proceed with our validation.
      */
     $errMsg = array();
     $errTrigger = null;
     $appsLib = CAppPlugins::getInstance();
     $appsLib->loadApplications();
     $params = array();
     $params[] = $post;
     $errTrigger = $appsLib->triggerEvent('onRegisterValidate', $params);
     if (is_null($errTrigger)) {
         //no trigger found.
         $errMsg = $this->_validateRegister($post);
     } else {
         if (!empty($errTrigger[0])) {
             $errMsg = $errTrigger[0];
         } else {
             // trigger found but no error return.
             $errMsg = $this->_validateRegister($post);
         }
     }
     if (count($errMsg) > 0) {
         //validation failed. show error message.
         foreach ($errMsg as $err) {
             $mainframe->enqueueMessage($err, 'error');
         }
         $this->register();
         return false;
     }
     // @rule: check with recaptcha
     $recaptcha = new CRecaptchaHelper();
     if (!$recaptcha->verify()) {
         JError::raiseWarning('', JText::_('COM_COMMUNITY_RECAPTCHA_MISMATCH'));
         $this->register();
         return false;
     }
     //adding to temp reg table.
     if (!$modelRegister->addTempUser($post)->return_value['addTempUser']) {
         JError::raiseWarning('', JText::_('COM_COMMUNITY_ERROR_IN_REGISTRATION'));
         $this->register();
         return false;
     }
     // Send the first email to inform user of their username and password
     $tmpUser = $modelRegister->getTempUser($token);
     $password = (string) $post['jspassword2'];
     //now we check whether there is any custom profile? if not, then we do the actual save here.
     $modelProfile = CFactory::getModel('profile');
     //get all published custom field for profile
     $filter = array('published' => '1', 'registration' => '1');
     $fields = $modelProfile->getAllFields($filter);
     $model = CFactory::getModel('Profile');
     $profileTypes = $model->getProfileTypes();
     // If there are no fields, we do not want to move to the edit profile area.
     if (count($fields) <= 0 && (!$profileTypes || !$config->get('profile_multiprofile'))) {
         //do the actual user save.
         $user = $this->_createUser($tmpUser);
         //update the first/last name if it exist in the profile configuration
         $this->_updateFirstLastName($user);
         $this->sendEmail('registration', $user, $password);
         // now we need to set it for later avatar upload page
         // do the clear up job for tmp user.
         $mySess->set('tmpUser', $user);
         $modelRegister->removeTempUser($token);
         $modelRegister->removeAuthKey($token);
         $usersConfig = $usersConfig = JComponentHelper::getParams('com_users');
         $useractivation = $usersConfig->get('useractivation');
         $this->sendEmail('registration_complete', $user, null, $useractivation);
         //redirect to avatar upload page.
         $mainframe->redirect(CRoute::_('index.php?option=com_community&view=register&task=registerAvatar', false));
     } else {
         $this->sendEmail('registration_uncomplete', $tmpUser, $password);
         //redirect to profile update page.
         // @rule: When there are no defined profile types, we will use the default.
         if (!$profileTypes || !$config->get('profile_multiprofile')) {
             $mainframe->redirect(CRoute::_('index.php?option=com_community&view=register&task=registerProfile&profileType=' . COMMUNITY_DEFAULT_PROFILE, false));
         } else {
             // Now that the username and name are properly entered, redirect them to select the profile type.
             $mainframe->redirect(CRoute::_('index.php?option=com_community&view=register&task=registerProfileType', false));
         }
     }
 }