Example #1
0
 public function register($data = null)
 {
     //require_once (JPATH_COMPONENT.'/libraries/profile.php');
     $mainframe = JFactory::getApplication();
     $my = CFactory::getUser();
     $config = CFactory::getConfig();
     /**
      * Opengraph
      */
     CHeadHelper::setType('website', JText::_('COM_COMMUNITY_REGISTER_NEW'));
     // Hide this form for logged in user
     if ($my->id) {
         $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_REGISTER_ALREADY_USER'), 'warning');
         return;
     }
     // If user registration is not allowed, show 403 not authorized.
     $usersConfig = JComponentHelper::getParams('com_users');
     if ($usersConfig->get('allowUserRegistration') == '0') {
         //show warning message
         $this->addWarning(JText::_('COM_COMMUNITY_REGISTRATION_DISABLED'));
         return;
     }
     $fields = array();
     $post = JRequest::get('post');
     $isUseFirstLastName = CUserHelper::isUseFirstLastName();
     $data = array();
     $data['fields'] = $fields;
     $data['html_field']['jsname'] = empty($post['jsname']) ? '' : $post['jsname'];
     $data['html_field']['jsusername'] = empty($post['jsusername']) ? '' : $post['jsusername'];
     $data['html_field']['jsemail'] = empty($post['jsemail']) ? '' : $post['jsemail'];
     $data['html_field']['jsfirstname'] = empty($post['jsfirstname']) ? '' : $post['jsfirstname'];
     $data['html_field']['jslastname'] = empty($post['jslastname']) ? '' : $post['jslastname'];
     // $js = 'assets/validate-1.5.min.js';
     // CFactory::attach($js, 'js');
     $recaptcha = new CRecaptchaHelper();
     $recaptchaHTML = $recaptcha->html();
     $fbHtml = '';
     if ($config->get('fbconnectkey') && $config->get('fbconnectsecret') && !$config->get('usejfbc')) {
         //CFactory::load( 'libraries' , 'facebook' );
         $facebook = new CFacebook();
         $fbHtml = $facebook->getLoginHTML();
     }
     if ($config->get('usejfbc')) {
         if (class_exists('JFBCFactory')) {
             $providers = JFBCFactory::getAllProviders();
             foreach ($providers as $p) {
                 $fbHtml .= $p->loginButton();
             }
         }
     }
     $tmpl = new CTemplate();
     $content = $tmpl->set('data', $data)->set('recaptchaHTML', $recaptchaHTML)->set('config', $config)->set('isUseFirstLastName', $isUseFirstLastName)->set('fbHtml', $fbHtml)->fetch('register/base');
     $appsLib = CAppPlugins::getInstance();
     $appsLib->loadApplications();
     $args = array(&$content);
     $appsLib->triggerEvent('onUserRegisterFormDisplay', $args);
     echo $this->_getProgressBar(1);
     echo $content;
 }
Example #2
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));
         }
     }
 }
 /**
  * Calls an HTTP POST function to verify if the user's guess was correct
  * @param string $privkey
  * @param string $remoteip
  * @param string $challenge
  * @param string $response
  * @param array $extra_params an array of extra variables to post to the server
  * @return ReCaptchaResponse
  */
 public static function recaptcha_check_answer($privkey, $remoteip, $challenge, $response, $extra_params = array())
 {
     if ($privkey == null || $privkey == '') {
         die("To use reCAPTCHA you must get an API key from <a href='http://recaptcha.net/api/getkey'>http://recaptcha.net/api/getkey</a>");
     }
     if ($remoteip == null || $remoteip == '') {
         die("For security reasons, you must pass the remote ip to reCAPTCHA");
     }
     //discard spam submissions
     if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
         $recaptcha_response = new ReCaptchaResponse();
         $recaptcha_response->is_valid = false;
         $recaptcha_response->error = 'incorrect-captcha-sol';
         return $recaptcha_response;
     }
     $response = CRecaptchaHelper::_recaptcha_http_post(RECAPTCHA_VERIFY_SERVER, "/verify", array('privatekey' => $privkey, 'remoteip' => $remoteip, 'challenge' => $challenge, 'response' => $response) + $extra_params);
     $answers = explode("\n", $response[1]);
     $recaptcha_response = new ReCaptchaResponse();
     if (trim($answers[0]) == 'true') {
         $recaptcha_response->is_valid = true;
     } else {
         $recaptcha_response->is_valid = false;
         $recaptcha_response->error = $answers[1];
     }
     return $recaptcha_response;
 }