Suppose if you are sending a newsletter to your customer with a link to your site, and if you want to autologin to your site when he click the link, then you cannot have this option in Joomla.
Thus I have created a function to accomplish this..
I will explain step by step about how to develop this,
First when the user clicks on the link, you need to make it to run a file, which will call this function below.
I have created this function when I am working with virtuemart.. And it is working right now without issues.
if you have trouble deploying this.. feel free to comment here :)
/* $d is an array which holds the userid and username.
$d["user_id"] = userid
$d["user_name"] = user name
*/
function quick_login($d){
global $mosConfig_absolute_path, $mosConfig_live_site,$_SESSION,$mainframe;;
if ($return = JRequest::getVar('return', '', 'method', 'base64')) {
$return = base64_decode($return);
if (!JURI::isInternal($return)) {
$return = '';
}
}
if( !isset($d['user_name']) || $d['user_name'] == ''){
$user = JUser::getInstance($d['user_id']);
$d['user_name'] = $user->username;
}
$options = array();
$options['remember'] = JRequest::getBool('remember', false);
$options['return'] = $return;
$credentials = array();
$credentials['username'] = $d['user_name'];
$credentials['password'] = '123'; //Give any thing
$mainframe->login($credentials);
$mainframe->redirect('index.php?option=com_user');
}
Dear Pallavan,
ReplyDeleteWould it be possible for you (paid service) to deploy this solution on our website?
Thank you in advance,
Stephja
Yes stephan I can deploy this on your website..
ReplyDeleteHi Pallava,
ReplyDeletePlease I need your help.
When I use the function, I have the following error:
Fatal error: Call to a member function login () on a non-object in C:\wamp\www\...
Please send me your email to reach you.
pedro.cfernandez@yahoo.com.ar
Thank you very much.
Pedro.