How to disable automatic login to Virtuemart after registration?

Started by mirovic, April 22, 2012, 17:02:05 PM

Previous topic - Next topic

mirovic

After new user sends Virtuemart registration form, is logged in Virtuemart somehow, but not in Joomla (appears welcome message in My account page). Is it possible to disable this function, so user must first login to Joomla to edit his details in Virtuemart and checkout?

In configuration of Virtuemart I have both settings about registration checked . In configuration of Rupostel One page checkout I have disabled these settings:

  • Log out shopper before and after purchase (from Joomla)
  • Enable duplicit emails in any type of registration
  • E-mail As Username


Virtuemart2.0.6, Joomla 2.5.4, Rupostel OnePage Checkout

Trompetteur

Do you have the answer of your question?
I also want to disable the auto login function, but don't know how...
I don't use the Rupostel OnePage Checkout.

pbc278

Same problem here

Joomla 2.5.4
Virtuemart 2.0.6

In checkoutprocess register as a new user, automatic logged into virtuemart BUT not logged into Joomla (my joomla login module still asks for username and pass, but should be showing the 'greeting message' also, just like Virtuemart does..

Anyone knows how to fix this, or disable the auto login?

pbc278

 :P I fixxed this issue in my Virtuemart 2.06 / Joomla 2.5.4 config.

go to the file: components\com_virtuemart\controllers\user.php
find this part:
if($currentUser->id==0){
$msg = (is_array($ret)) ? $ret['message'] : $ret;
$usersConfig = &JComponentHelper::getParams( 'com_users' );
$useractivation = $usersConfig->get( 'useractivation' );
if (is_array($ret) && $ret['success'] && !$useractivation) {
// Username and password must be passed in an array
$credentials = array('username' => $ret['user']->username,
  'password' => $ret['user']->password_clear
);
$return = $mainframe->login($credentials);


This part should do the correct login, but it is skipped completely because when it reaches this part the variable '$currentUser' is never '0', but has the value of the new user ID that is created when the entered userdata is stored... SO, first change the first line to:

if($currentUser->id!=0){

then you can see the return of this part sould be the login action, but the line '$return = $mainframe->login($credentials);' does not do anything, change it also to:

return $mainframe->login($credentials);

After this you are correctly logged into Joomla and Virtuemart 2!

I'm not a VM developer, but I hope this fix makes any sense and I also hope my logic is correct !?

pbc278

Quote from: pbc278 on June 15, 2012, 01:27:55 AM
then you can see the return of this part sould be the login action, but the line '$return = $mainframe->login($credentials);' does not do anything, change it also to:

This part was correct, sorry, did not know do a 'return' this way...
I was learned to write "return bla bla bla;" and not "$return = bla bla bla;"

sorry  :-[

Trompetteur

I'm still looking for a solution. After a new user registration, the user is automatically logged in. I would like to disable that, so that the user only can login after he has clicked the activation link in his registration mail.

VM 2.0.6
Joomla 2.5.4

Any help?

cavalier79

Hello all! Any news for this?

Do someone know how to register and NOT login ??

shunsui

i have this problem too, and the solution above does not work for self-activation, activation link dont work because user is login already in VM  :-\



cavalier79

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...


Ziguri

Hello,

None of this solutions works for me... does anyone has another solution for this?

There is any way to just disable the virtuemart automatic login right after the registration?

Thanks


gpessoa

Same problem here!
User create an account, and stay automatically login. But this is not a valid login!
When clicking the confirmation/ activation e-mail login account, the link doesn’t work.

Joomla 2.58
VM 2.014
J 3.10.5; VM 3.4.2; PHP 7.2.34


czuryk

I create solution.

At First. Need apply this simple hack:
in this file \components\com_users\models\registration.php
search this string in code: // Get the user id based on the token.
and change code block like this
$db->setQuery(
'SELECT '.$db->quoteName('id').' FROM '.$db->quoteName('#__users') .
' WHERE '.$db->quoteName('activation').' = '.$db->Quote($token) .
' AND '.$db->quoteName('block').' = 1' .
// ' AND '.$db->quoteName('lastvisitDate').' = '.$db->Quote($db->getNullDate())
''
);

this hack need for correct activation from VM2 mail.

And this code paste to your template at the top:

$user =& JFactory::getUser();

if ( ($user->block == 1) && ($user->id != 0) ) {
$app = JFactory::getApplication();
$app->logout( $user->id );
$app->redirect("index.php?option=com_virtuemart", "Need activation text...");
}


Simple and clever.
Tested on VM 2.0.16