V
V
Vanes Ri_Lax2020-09-23 08:48:49
Joomla
Vanes Ri_Lax, 2020-09-23 08:48:49

How to embed recaptcha 2 on joomla 1.5?

Good afternoon!
The task came to embed recaptcha 2 on joomla 1.5, namely, it should be in the form when registering users!
I took this plugin as a basis:
https://github.com/milkycode/joomla_recaptcha_j15
Next, I opened the file at:

/components/com_user/views/register/tmpl/default.php

I added the following code to the form:
<tr>
  <td colspan="2">
    <?php echo ReCaptcha::get('html'); ?>
  </td>
</tr>

In the admin panel, I registered the public and secret keys.
As a result, I got a recaptcha in the form.
Next, I opened the file: I
/components/com_user/controller.php
found a function in it:
function register_save()
  {
    global $mainframe;

    // Check for request forgeries
    JRequest::checkToken() or jexit( 'Invalid Token' );

    // Get required system objects
    $user 		= clone(JFactory::getUser());
    $pathway 	=& $mainframe->getPathway();
    $config		=& JFactory::getConfig();
    $authorize	=& JFactory::getACL();
    $document   =& JFactory::getDocument();

    // If user registration is not allowed, show 403 not authorized.
    $usersConfig = &JComponentHelper::getParams( 'com_users' );
    if ($usersConfig->get('allowUserRegistration') == '0') {
      JError::raiseError( 403, JText::_( 'Access Forbidden' ));
      return;
    }

    // Initialize new usertype setting
    $newUsertype = $usersConfig->get( 'new_usertype' );
    if (!$newUsertype) {
      $newUsertype = 'Registered';
    }

    // Bind the post array to the user object
    if (!$user->bind( JRequest::get('post'), 'usertype' )) {
      JError::raiseError( 500, $user->getError());
    }

    // Set some initial user values
    $user->set('id', 0);
    $user->set('usertype', $newUsertype);
    $user->set('gid', $authorize->get_group_id( '', $newUsertype, 'ARO' ));

    $date =& JFactory::getDate();
    $user->set('registerDate', $date->toMySQL());

    // If user activation is turned on, we need to set the activation information
    $useractivation = $usersConfig->get( 'useractivation' );
    if ($useractivation == '1')
    {
      jimport('joomla.user.helper');
      $user->set('activation', JUtility::getHash( JUserHelper::genRandomPassword()) );
      $user->set('block', '1');
    }

    // If there was an error with registration, set the message and display form

    if (ReCaptcha::get('submit')) { // 
      if (!ReCaptcha::get('success')) {
        JError::raiseWarning('', 'Неверный код проверки!'); //если не верно выводим сообщение
        $this->register(); 
        return false;
       }else{
      if ( !$user->save() )
      {
        JError::raiseWarning('', JText::_( $user->getError()));
        $this->register();
        return false;
      }
  
      // Send registration confirmation mail
      $password = JRequest::getString('password', '', 'post', JREQUEST_ALLOWRAW);
      $password = preg_replace('/[\x00-\x1F\x7F]/', '', $password); //Disallow control chars in the email
      UserController::_sendMail($user, $password);
  
      // Everything went fine, set relevant message depending upon user activation state and display message
      if ( $useractivation == 1 ) {
        $message  = JText::_( 'REG_COMPLETE_ACTIVATE' );
      } else {
        $message = JText::_( 'REG_COMPLETE' );
      }
  
      $this->setRedirect('index.php', $message);
       }
     }else{
    print_r(ReCaptcha::get('submit'));
    JError::raiseWarning('', 'Не удалось проверить капчу!'); //если не верно выводим сообщение
    $this->register(); 
    return false;
     }
  }

All captcha checking takes place here:
if (ReCaptcha::get('submit')) { // 
      if (!ReCaptcha::get('success')) {
        JError::raiseWarning('', 'Неверный код проверки!'); //если не верно выводим сообщение
        $this->register(); 
        return false;
       }else{
      if ( !$user->save() )
      {
        JError::raiseWarning('', JText::_( $user->getError()));
        $this->register();
        return false;
      }
  
      // Send registration confirmation mail
      $password = JRequest::getString('password', '', 'post', JREQUEST_ALLOWRAW);
      $password = preg_replace('/[\x00-\x1F\x7F]/', '', $password); //Disallow control chars in the email
      UserController::_sendMail($user, $password);
  
      // Everything went fine, set relevant message depending upon user activation state and display message
      if ( $useractivation == 1 ) {
        $message  = JText::_( 'REG_COMPLETE_ACTIVATE' );
      } else {
        $message = JText::_( 'REG_COMPLETE' );
      }
  
      $this->setRedirect('index.php', $message);
       }
     }else{
    print_r(ReCaptcha::get('submit'));
    JError::raiseWarning('', 'Не удалось проверить капчу!'); //если не верно выводим сообщение
    $this->register(); 
    return false;
     }

For some reason, this condition is not met for me: And the code is executed:
if (ReCaptcha::get('submit'))
}else{
    print_r(ReCaptcha::get('submit'));
    JError::raiseWarning('', 'Не удалось проверить капчу!'); //если не верно выводим сообщение
    $this->register(); 
    return false;
     }

What am I doing wrong? Thank you very much in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sashabeep, 2020-09-23
@sashabeep

Anyone else using Joomla 1.5?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question