VirtueMart Forum

VirtueMart 2 + 3 + 4 => Administration & Configuration => Topic started by: mirovic on April 22, 2012, 17:02:05 PM

Title: How to disable automatic login to Virtuemart after registration?
Post by: mirovic on April 22, 2012, 17:02:05 PM
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:


Virtuemart2.0.6, Joomla 2.5.4, Rupostel OnePage Checkout
Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: Trompetteur on May 21, 2012, 15:54:46 PM
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.
Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: pbc278 on June 14, 2012, 16:32:46 PM
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?
Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: pbc278 on June 15, 2012, 01:27:55 AM
 :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 !?
Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: pbc278 on June 15, 2012, 01:39:52 AM
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  :-[
Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: Trompetteur on August 16, 2012, 17:27:22 PM
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?
Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: cavalier79 on August 27, 2012, 18:30:49 PM
Hello all! Any news for this?

Do someone know how to register and NOT login ??
Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: shunsui on September 04, 2012, 08:10:27 AM
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  :-\
Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: Setko on September 16, 2012, 11:42:36 AM
Did anyone solve this problem?
Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: paping on September 24, 2012, 09:15:54 AM
Hello all! Any update on this issue?
Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: cavalier79 on October 12, 2012, 14:49:45 PM
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...

Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: Ziguri on November 04, 2012, 18:58:42 PM
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

Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: gpessoa on December 02, 2012, 20:24:34 PM
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
Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: garda on January 02, 2013, 19:06:50 PM
Did someone find a solution?
Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: czuryk on January 06, 2013, 17:06:48 PM
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
Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: drejk on February 18, 2013, 20:01:40 PM
Simple solution (VirtueMart bug?)

in administrator/components/com_virtuemart/models/user.php, in function store(), line approx. 494, change
$user = JFactory::getUser();
to
$user = new JUser;

(works on 2.0.14)
Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: Stonedfury on March 20, 2013, 23:06:09 PM
What's the fix to 2.0.20b? lol
Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: Stonedfury on March 21, 2013, 17:50:52 PM
Quote from: pbc278 on June 15, 2012, 01:39:52 AM
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  :-[
Has anyone else tried this? I don't mind the customer being logged in after registering as that just makes it simpler. But not being logged in completely is a problem.

VM should get along with joomla not the other way. Joomla is by far a superior and more reliable product so why not use their standards literally.

This is what my user.php has
if($currentUser->guest==1){

$msg = (is_array($ret)) ? $ret['message'] : $ret;

$usersConfig = JComponentHelper::getParams( 'com_users' );

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

if (is_array($ret) and $ret['success'] and !$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);

}

The user is not being logged into joomla but they are logged in. We did a customer over the phone today and I watched as they checked out and they were never logged in and still show as "logged in - Never" I have searched for the code if($currentUser->id==0){ and it doesn't exist in that file so I am hoping to be safe in assuming that the VM devs tried to fix it but still failed. :(
My VM is 2.0.20b joomla 2.5.9 php 5.3
Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: jenkinhill on March 22, 2013, 10:17:34 AM
I want all shoppers to be logged in to VM immediately so they can complete the purchase without being put off. To get users registered in Joomla too the solution for most people is here: http://forum.virtuemart.net/index.php?topic=113802.0    No need to hack any core files.
Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: Stonedfury on March 23, 2013, 21:05:57 PM
Quote from: jenkinhill on March 22, 2013, 10:17:34 AM
I want all shoppers to be logged in to VM immediately so they can complete the purchase without being put off. To get users registered in Joomla too the solution for most people is here: http://forum.virtuemart.net/index.php?topic=113802.0    No need to hack any core files.
Thank you Jenkin! I will give this a shot as I agree I want them to be logged in to VM and JM. We do not do email activation as they will be paying with a card or PayPal and leaving. The activation email deters them and you can kiss most of those customers good bye.
Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: zomby688 on July 26, 2013, 14:31:00 PM
if still intersting , i solved this problem more simple. All this threads not solve this problem, because user still not login in joomla after registration and autologin in vm. I make authorization through joomla module only and it's  important for me. I made force logout on order_done page by adding this code in com_virtuemart\cart\order_done.php:

<?php
$currentUser 
JFactory::getUser()
if (
$currentUser->guest) {
$app JFactory::getApplication();
$app->logout();
}
?>


it's part of code from post above and you can apply it to your template and no hack need
Sry my english.
Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: AnSit on July 27, 2013, 11:37:18 AM
Quote from: jenkinhill on March 22, 2013, 10:17:34 AM
I want all shoppers to be logged in to VM immediately so they can complete the purchase without being put off.

Good day to all!
Raised a very important topic!
I agree that the buyer should be able to as quickly as possible to make the order.
But equally important is the feedback from them!

After all, he created the VM so that correspond with the buyer. It is very important notice about the change of status of order. It's easy! On the phone is not an option to do so. And uncomfortable.

And as the activation time is needed in order to confirm the correct mailbox. Thus activation of the guarantee to the user.

If an order can be issued without activation and registration or wrong mailbox, then there are no guarantees. Yes and no account in Joomla that I can contact someone to do newsletters and the like. If the user makes a mistake and accidentally have the wrong mailbox it will not receive a letter of confirmation of order and therefore will not be able to get it.

The problem is not even that activation does not go well, and that it is possible to place an order without a full registration.

I beg you to make at least an option that would allow the permit or deny ordering without activation / registration!

Otherwise makes no sense option: "Only registered users can checkout"!

And many thanks to the developers for the VM and their work!
Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: Stallion on January 31, 2014, 15:56:13 PM
Seriously guys of VM you should consider adding an option (checkbox in configuration) to disable vm auto login.

Activation link does not work because of session variables and it is pretty annoying....

Does anyone have a fix for this????
Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: BrownSystems on December 18, 2014, 22:49:49 PM
I ended up using a combination of the hacks proposed by cavalier79 and czuryk. I believe they would both work independently just fine.

I faced a scenario in which I needed to require account activation via email before a user was able to access their account. Obviously the auto login was not acceptable because the requirement was to have users activate before accessing their account. In addition to this issue I also found that the account activation link would not work. So I had to modify the users registration model as described by cavalier79 and czuryk.

I'm not sure if this is still an issue in VM as I am using a dated and heavily hacked version of Virtuemart but it seems to me that the account activation feature wasn't created in a logical manner. I can't think of any scenario in which you would want to require account activation yet allow access to the account immediately after registration.

I initially attempted to figure out where VM is establishing the auto login but I ended up giving up and using this ugly hack. It would be nice if VM developers would provide the location of where the auto login happens or even better provide a config setting to disable this. 
Title: Re: How to disable automatic login to Virtuemart after registration?
Post by: anksuthar on May 05, 2016, 09:30:17 AM
It is solved by hack in Virtuemart file hack also working if user activate account by him-self  through email no need to core joomla file hack only hack in virtuemart

I m solve this issue in  VirtueMart 3.0.12  other version may be some different code.


in file path "components\com_virtuemart\controllers\user.php"
find function
private function saveData($cartObj) {

}


then in function
$switch = false;
            if($currentUser->guest==1 and $register){
               $userModel->setId(0);
               $superUser = vmAccess::isSuperVendor();
               if($superUser>1){
                  $data['vendorId'] = $superUser;
               }
               $switch = true;
            }
                               
Add again "$switch = false;"  for stop session
                                $switch = false;

and find
$return = $mainframe->login($credentials);
and comment them

//$return = $mainframe->login($credentials);