MyBlogPlanner

Auto Login Joomla function

Wednesday, May 27th, 2009

One of my client always like to sent mail to his members with updates of the website to make them participate. For long time he was demanded me a auto login system in joomla.

Today at last we got the solution how we can do it. I am sharing this with you hope that may help a lot of people.

function FnAutoLogin($ActivateID)
{

global $mainframe;
$db = JFactory::getDBO();
$Password =  FnGenerateNewPassword(’9′); // Generating joomla password

//Fetching User Details according to Activation ID start

$query = “select * from #__users where activation=’”.$ActivateID.”‘”;
$db->setQuery( $query );
$UserDetailsInArray = $db->loadObjectList();

//Fetching User Details according to Activation ID end

if(isset($UserDetailsInArray[0]))
{
$TempPassword = $UserDetailsInArray[0]->password;   // Storing user actual password

$query1 = “update #__users set password=’”.$Password.”‘ where activation =’”.$id.”‘”; //Updating temporary password
$db->setQuery( $query1 );
if($db->query())
{
//                      User Login start

$usersipass[’username’] = $UserDetailsInArray[0]->username;
$usersipass[’password’] = ‘9′;
$mainframe->login($usersipass);

//                      User Login end
$query1 = “update #__users set password=’”.$TempPassword.”‘, block=0 where activation =’”.$ActivateID.”‘”; //Update user actual password againand redirect to your appropriate page you like :)
$db->setQuery( $query1 );
if($db->query())
{
$Msg = ‘Please upload your picture to see your profile.’;
$mainframe->redirect( ‘index.html’,$Msg);
}
}
}
else
{
echo ‘You don\’t have account yet? <a href=”/join.html”>Join Us Today </a>’;
}
}

Hope this will help a lot of developer to make auto login system in joomla. :)