Inserindo em outro banco de dados após o registro

  • skindedo
  • Avatar de skindedo Autor do Tópico
  • Offline
  • JCB! Novato
  • JCB! Novato
Mais
9 anos 4 meses atrás #98355 por skindedo
skindedo created the topic: Inserindo em outro banco de dados após o registro
eai galera... estou fazendo uma nova inserção em um banco de dados separado do joomla. O usuário depois de cadastrado no site é cadastrado em um banco de dados postgrees para acesso a outro sistema, mas não estou conseguindo.. o código funciona em uma página separada mas dentro da página do registro ele não funciona..

estou usando o joomla 3 ... o arquivo que estou modificando se encontra na pasta:
components\com_users\controllers\registration.php

segue o código
//skindedo -- conexão com postgrees para inserção no scriptcase pós verificação de e-mail
         $bdcon2 = pg_connect('host=192.168.7.115 dbname=gf_recrut_selec user=postgres password=********') or die('Could not connect: ' . pg_last_error());
         // skindedo - inserção no scriptcase pós verificação de e-mail
         $q = pg_query($bdcon2, "INSERT INTO tb_usr(nm_mail_usr, vl_senh, vl_senh_antr, in_conf_mail, dt_cria_reg, dt_atlz_reg) VALUES ('teste', 'teste', 'teste', '1', NULL, NULL)");

         pg_close($bdcon2);
         //fim

testei o código em uma página separada e funcionou..
mas quando coloco ele dentro do arquivo ele não funciona.. parece que o joomla ignora o código de inserção no outro banco..
segue o arquivo com o código inserido..
<?php
/**
 * @package     Joomla.Site
 * @subpackage  com_users
 *
 * @copyright   Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

require_once JPATH_COMPONENT . '/controller.php';

/**
 * Registration controller class for Users.
 *
 * @package     Joomla.Site
 * @subpackage  com_users
 * @since       1.6
 */
 




class UsersControllerRegistration extends UsersController
{
   /**
    * Method to activate a user.
    *
    * @return  boolean  True on success, false on failure.
    *
    * @since   1.6
    */
   public function activate()
   {
      $user      = JFactory::getUser();
      $input     = JFactory::getApplication()->input;
      $uParams = JComponentHelper::getParams('com_users');

      // Check for admin activation. Don't allow non-super-admin to delete a super admin
      if ($uParams->get('useractivation') != 2 && $user->get('id'))
      {
         $this->setRedirect('index.php');

         return true;
      }

      // If user registration or account activation is disabled, throw a 403.
      if ($uParams->get('useractivation') == 0 || $uParams->get('allowUserRegistration') == 0)
      {
         JError::raiseError(403, JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));

         return false;
      }

      $model = $this->getModel('Registration', 'UsersModel');
      $token = $input->getAlnum('token');

      // Check that the token is in a valid format.
      if ($token === null || strlen($token) !== 32)
      {
         JError::raiseError(403, JText::_('JINVALID_TOKEN'));

         return false;
      }

      // Attempt to activate the user.
      $return = $model->activate($token);

      // Check for errors.
      if ($return === false)
      {
         // Redirect back to the homepage.
         $this->setMessage(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $model->getError()), 'warning');
         $this->setRedirect('index.php');

         return false;
      }

      $useractivation = $uParams->get('useractivation');

      // Redirect to the login screen.
      if ($useractivation == 0)
      {
         $this->setMessage(JText::_('COM_USERS_REGISTRATION_SAVE_SUCCESS'));
         $this->setRedirect(JRoute::_('index.php?option=com_users&view=login', false));
      }
      elseif ($useractivation == 1)
      {
         $this->setMessage(JText::_('COM_USERS_REGISTRATION_ACTIVATE_SUCCESS'));
         $this->setRedirect(JRoute::_('index.php?option=com_users&view=login', false));
      }
      elseif ($return->getParam('activate'))
      {
         //skindedo -- conexão com postgrees para inserção no scriptcase pós verificação de e-mail
         $bdcon2 = pg_connect('host=192.168.7.115 dbname=gf_recrut_selec user=postgres password=********') or die('Could not connect: ' . pg_last_error());
         // skindedo - inserção no scriptcase pós verificação de e-mail
         $q = pg_query($bdcon2, "INSERT INTO tb_usr(nm_mail_usr, vl_senh, vl_senh_antr, in_conf_mail, dt_cria_reg, dt_atlz_reg) VALUES ('teste', 'teste', 'teste', '1', NULL, NULL)");

         pg_close($bdcon2);
         //fim             

         $this->setMessage(JText::_('COM_USERS_REGISTRATION_VERIFY_SUCCESS'));
         $this->setRedirect(JRoute::_('index.php?option=com_users&view=registration&layout=complete', false));
      }
      else
      {
         $this->setMessage(JText::_('COM_USERS_REGISTRATION_ADMINACTIVATE_SUCCESS'));
         $this->setRedirect(JRoute::_('index.php?option=com_users&view=registration&layout=complete', false));
      }

      return true;
   }

   /**
    * Method to register a user.
    *
    * @return  boolean  True on success, false on failure.
    *
    * @since   1.6
    */
   public function register()
   {
      // Check for request forgeries.
      JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));

      // If registration is disabled - Redirect to login page.
      if (JComponentHelper::getParams('com_users')->get('allowUserRegistration') == 0)
      {
         $this->setRedirect(JRoute::_('index.php?option=com_users&view=login', false));

         return false;
      }

      $app   = JFactory::getApplication();
      $model   = $this->getModel('Registration', 'UsersModel');

      // Get the user data.
      $requestData = $this->input->post->get('jform', array(), 'array');

      // Validate the posted data.
      $form   = $model->getForm();

      if (!$form)
      {
         JError::raiseError(500, $model->getError());

         return false;
      }

      $data   = $model->validate($form, $requestData);

      // Check for validation errors.
      if ($data === false)
      {
         // Get the validation messages.
         $errors   = $model->getErrors();

         // Push up to three validation messages out to the user.
         for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++)
         {
            if ($errors&#91;$i&#93; instanceof Exception)
            {
               $app->enqueueMessage($errors&#91;$i&#93;->getMessage(), 'warning');
            }
            else
            {
               $app->enqueueMessage($errors&#91;$i&#93;, 'warning');
            }
         }

         // Save the data in the session.
         $app->setUserState('com_users.registration.data', $requestData);

         // Redirect back to the registration screen.
         $this->setRedirect(JRoute::_('index.php?option=com_users&view=registration', false));

         return false;
      }

      // Attempt to save the data.
      $return   = $model->register($data);

      // Check for errors.
      if ($return === false)
      {
         // Save the data in the session.
         $app->setUserState('com_users.registration.data', $data);

         // Redirect back to the edit screen.
         $this->setMessage($model->getError(), 'warning');
         $this->setRedirect(JRoute::_('index.php?option=com_users&view=registration', false));

         return false;
      }

      // Flush the data from the session.
      $app->setUserState('com_users.registration.data', null);

      // Redirect to the profile screen.
      if ($return === 'adminactivate')
      {
         $this->setMessage(JText::_('COM_USERS_REGISTRATION_COMPLETE_VERIFY'));
         $this->setRedirect(JRoute::_('index.php?option=com_users&view=registration&layout=complete', false));
      }
      elseif ($return === 'useractivate')
      {
         //skindedobusca informações sobre o usuário
         //$user = JFactory::getUser($user->get('id'));
         
            $this->setMessage(JText::_('COM_USERS_REGISTRATION_COMPLETE_ACTIVATE'));
            $this->setRedirect(JRoute::_('index.php?option=com_users&view=registration&layout=complete', false));   
         
      }
      else
      {
         $this->setMessage(JText::_('COM_USERS_REGISTRATION_SAVE_SUCCESS'));
         $this->setRedirect(JRoute::_('index.php?option=com_users&view=login', false));
      }

      return true;
   }
}

Please Entrar ou Registrar to join the conversation.