Hello all.
I found this solution.
It's a hack on the code.
com_virtuemart/controller/user.php
changed function saveUser to :
$arr = $this->savaData(false, true);
if($arr['new'] == 'NEWUSER') {
JFactory::getApplication()->logout();
$this->setRedirect( JRoute::_('index.php?option=COM_MYCUSTOMCOMPONENT') );
} else {
$this->setRedirect( JRoute::_('index.php?option=com_virtuemart&view=user&layout=edit') );
}
in MYCUSTOMCOMPONENT I create a view for displaying a successfull registration.
then in saveData() change to :
private function savaData($cart=false,$register=false){
// echo "<pre>saveData()</pre>";
$mainframe = JFactory::getApplication();
$currentUser = JFactory::getUser();
$msg = '';
$data = JRequest::get('post');
$data['address_type'] = JRequest::getWord('addrtype','BT');
$this->saveToCart($data);
if (!class_exists('VirtueMartCart')) require(JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php');
$carrello = VirtueMartCart::getCart(false);
if($register && $currentUser->guest == 1) {
$this->addModelPath( JPATH_VM_ADMINISTRATOR.DS.'models' );
$userModel = VmModel::getModel('user');
if(!$cart){
// Store multiple selectlist entries as a ; separated string
if (key_exists('vendor_accepted_currencies', $data) && is_array($data['vendor_accepted_currencies'])) {
$data['vendor_accepted_currencies'] = implode(',', $data['vendor_accepted_currencies']);
}
$data['vendor_store_name'] = JRequest::getVar('vendor_store_name','','post','STRING',JREQUEST_ALLOWHTML);
$data['vendor_store_desc'] = JRequest::getVar('vendor_store_desc','','post','STRING',JREQUEST_ALLOWHTML);
$data['vendor_terms_of_service'] = JRequest::getVar('vendor_terms_of_service','','post','STRING',JREQUEST_ALLOWHTML);
}
$msg = $userModel->store($data);
$carrello->setCartIntoSession();
$ret = array('msg' => $msg, 'new' => 'NEWUSER');
return $ret;
} else if($currentUser->guest != 1) {
$this->addModelPath( JPATH_VM_ADMINISTRATOR.DS.'models' );
$userModel = VmModel::getModel('user');
if(!$cart){
// Store multiple selectlist entries as a ; separated string
if (key_exists('vendor_accepted_currencies', $data) && is_array($data['vendor_accepted_currencies'])) {
$data['vendor_accepted_currencies'] = implode(',', $data['vendor_accepted_currencies']);
}
$data['vendor_store_name'] = JRequest::getVar('vendor_store_name','','post','STRING',JREQUEST_ALLOWHTML);
$data['vendor_store_desc'] = JRequest::getVar('vendor_store_desc','','post','STRING',JREQUEST_ALLOWHTML);
$data['vendor_terms_of_service'] = JRequest::getVar('vendor_terms_of_service','','post','STRING',JREQUEST_ALLOWHTML);
}
//It should always be stored
return $userModel->store($data);
}
And finally in view.html.php of customcompoennt i put this :
class MontiViewMonti extends JView {
public function display($tpl = null)
{
$app = JFactory::getApplication();
$app->logout();
unset($_SESSION['__vm']);
$lang = JFactory::getLanguage();
$lang->load('com_virtuemart');
parent::display($tpl);
}
}
I force the logout and unset the __vm session.
If the user registration is under activation (activate trough email) we've also to change this :
com_users/model/registration.php
public function activate($token)
{
$config = JFactory::getConfig();
$userParams = JComponentHelper::getParams('com_users');
$db = $this->getDbo();
// Get the user id based on the token.
$db->setQuery(
'SELECT '.$db->quoteName('id').' FROM '.$db->quoteName('#__users') .
' WHERE '.$db->quoteName('activation').' = '.$db->Quote($token) .
' AND '.$db->quoteName('block').' = 1'
);
/* removed .' AND '.$db->quoteName('lastvisitDate').' = '.$db->Quote($db->getNullDate())*/
$userId = (int) $db->loadResult();
// Check for a valid user id.
if (!$userId) {
$this->setError(JText::_('COM_USERS_ACTIVATION_TOKEN_NOT_FOUND'));
return false;
}
// Load the users plugin group.
JPluginHelper::importPlugin('user');
// Activate the user.
$user = JFactory::getUser($userId);
// Admin activation is on and user is verifying their email
if (($userParams->get('useractivation') == 2) && !$user->getParam('activate', 0))
{
$uri = JURI::getInstance();
// Compile the admin notification mail values.
$data = $user->getProperties();
$data['activation'] = JApplication::getHash(JUserHelper::genRandomPassword());
$user->set('activation', $data['activation']);
$data['siteurl'] = JUri::base();
$base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
$data['activate'] = $base.JRoute::_('index.php?option=com_users&task=registration.activate&token='.$data['activation'], false);
$data['fromname'] = $config->get('fromname');
$data['mailfrom'] = $config->get('mailfrom');
$data['sitename'] = $config->get('sitename');
$user->setParam('activate', 1);
$emailSubject = JText::sprintf(
'COM_USERS_EMAIL_ACTIVATE_WITH_ADMIN_ACTIVATION_SUBJECT',
$data['name'],
$data['sitename']
);
$emailBody = JText::sprintf(
'COM_USERS_EMAIL_ACTIVATE_WITH_ADMIN_ACTIVATION_BODY',
$data['sitename'],
$data['name'],
$data['email'],
$data['username'],
$data['siteurl'].'index.php?option=com_users&task=registration.activate&token='.$data['activation']
);
// get all admin users
$query = 'SELECT name, email, sendEmail, id' .
' FROM #__users' .
' WHERE sendEmail=1';
$db->setQuery( $query );
$rows = $db->loadObjectList();
// Send mail to all users with users creating permissions and receiving system emails
foreach( $rows as $row )
{
$usercreator = JFactory::getUser($id = $row->id);
if ($usercreator->authorise('core.create', 'com_users'))
{
$return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $row->email, $emailSubject, $emailBody);
// Check for an error.
if ($return !== true) {
$this->setError(JText::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED'));
return false;
}
}
}
}
//Admin activation is on and admin is activating the account
elseif (($userParams->get('useractivation') == 2) && $user->getParam('activate', 0))
{
$user->set('activation', '');
$user->set('block', '0');
$uri = JURI::getInstance();
// Compile the user activated notification mail values.
$data = $user->getProperties();
$user->setParam('activate', 0);
$data['fromname'] = $config->get('fromname');
$data['mailfrom'] = $config->get('mailfrom');
$data['sitename'] = $config->get('sitename');
$data['siteurl'] = JUri::base();
$emailSubject = JText::sprintf(
'COM_USERS_EMAIL_ACTIVATED_BY_ADMIN_ACTIVATION_SUBJECT',
$data['name'],
$data['sitename']
);
$emailBody = JText::sprintf(
'COM_USERS_EMAIL_ACTIVATED_BY_ADMIN_ACTIVATION_BODY',
$data['name'],
$data['siteurl'],
$data['username']
);
$return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody);
// Check for an error.
if ($return !== true) {
$this->setError(JText::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED'));
return false;
}
}
else
{
$user->set('activation', '');
$user->set('block', '0');
}
// Store the user object.
if (!$user->save()) {
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_ACTIVATION_SAVE_FAILED', $user->getError()));
return false;
}
return $user;
}
because VM made a phantom login when it register a user and set the last visit date so the activation link doesn't work.
Obviously this is my personal hack and it will not work after a update...