//log user in
if(!JFactory::getUser()->id)
{
$email = (string)$response['linkedin']->{'email-address'};
$db = JFactory::getDbo();
$app = JFactory::getApplication();
$sql = "SELECT * FROM #__users WHERE email = " . $db->quote($email);
$db->setQuery($sql);
$result = $db->loadObject();
if($result->id)
{
$jUser = JFactory::getUser($result->id);
//$userarray = array();
//$userarray['username'] = $jUser->username;
//$userarray['password'] = $jUser->password;
//$app->login($userarray);
$instance = $jUser;
$instance->set('guest', 0);
// Register the needed session variables
$session =& JFactory::getSession();
$session->set('user',$jUser);
// Check to see the the session already exists.
$app->checkSession();
// Update the user related fields for the Joomla sessions table.
$db->setQuery(
'UPDATE '.$db->quoteName('#__session') .
' SET '.$db->quoteName('guest').' = '.$db->quote($instance->get('guest')).',' .
' '.$db->quoteName('username').' = '.$db->quote($instance->get('username')).',' .
' '.$db->quoteName('userid').' = '.(int) $instance->get('id') .
' WHERE '.$db->quoteName('session_id').' = '.$db->quote($session->getId())
);
$db->query();
// Hit the user last visit field
$instance->setLastVisit();
//return true;
$app->redirect('index.php?option=com_community&view=profile');
}
else
{
$url = "index.php?option=com_community&view=register";
$app->redirect($url,'We did not find your email address in our system. Please register.');
//echo "redirect to registration page";
//exit();
//$url = 'index.php?option=com_users&view=registration&name=' . $user_profile['name'] . '&username=' . $user_profile['username'] . '&email=' . $user_profile['email'];
//$url = JRoute::_($url);
//$app->redirect($url);
}
}