Deperately need help with PHP logout/login code via API - Joomla! Forum - community, help and support
i have specifc need.
i need logout current joomla user log them in using same credentials. have project civicrm , extending functionality of product. have custom form displays civicrm contacts of email address, civicrm tags userid of joomla 1 contact of civicrm. circumvent have coded system programatically swap relationship on fly user selects contact edit.
the problem civiccrm cache cannot purged current user (just system wide) (i've posted , discussed devs in forums) , thats backdrop...
so way clear civicrm cache , work log out , log in , new relationship set. have set when select different contact system logs them out code:
$app = jfactory::getapplication();
$user = jfactory::getuser();
$user_id = $user->get('id');
$app->logout($user_id, array());
i need programatic way log user in no interaction either storing credentials in cookie , relogging them in , deleting cookie or in php. not knowegeable enough joomla api accomplish task. there way reload joomla cache user? or there anyway simulate this? masking part of projects short coming displaying "verify credentials" re-login page, crude , annoying works. i'm looking make whole process transparent. had thought coding own login page , capturing username password in encrypted cookie later api usage wanted ping experts , see if there better way.
can me, literally last piece of extensive project.
this code i've been playing 1.5 , of course im on 2.5 think need 1.6/1.7 compatible version
best regards,
david
i need logout current joomla user log them in using same credentials. have project civicrm , extending functionality of product. have custom form displays civicrm contacts of email address, civicrm tags userid of joomla 1 contact of civicrm. circumvent have coded system programatically swap relationship on fly user selects contact edit.
the problem civiccrm cache cannot purged current user (just system wide) (i've posted , discussed devs in forums) , thats backdrop...
so way clear civicrm cache , work log out , log in , new relationship set. have set when select different contact system logs them out code:
$app = jfactory::getapplication();
$user = jfactory::getuser();
$user_id = $user->get('id');
$app->logout($user_id, array());
i need programatic way log user in no interaction either storing credentials in cookie , relogging them in , deleting cookie or in php. not knowegeable enough joomla api accomplish task. there way reload joomla cache user? or there anyway simulate this? masking part of projects short coming displaying "verify credentials" re-login page, crude , annoying works. i'm looking make whole process transparent. had thought coding own login page , capturing username password in encrypted cookie later api usage wanted ping experts , see if there better way.
can me, literally last piece of extensive project.
this code i've been playing 1.5 , of course im on 2.5 think need 1.6/1.7 compatible version
code: select all
if(!jfactory::getuser()->id)
{
$email = (string)$response['linkedin']->{'email-address'};
$db = jfactory::getdbo();
$app = jfactory::getapplication();
$sql = "select * #__users 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);
$instance->set('aid', 1);
$instance->set('usertype', 'registered');
// register needed session variables
$session->set('user',$instance);
// check see the session exists.
//$app->checksession();
//$app->_createsession($session->getid());
// update user related fields joomla sessions table.
/*$db->setquery(
'update '.$db->namequote('#__session') .
' set '.$db->namequote('guest').' = '.$db->quote($instance->get('guest')).',' .
' '.$db->namequote('username').' = '.$db->quote($instance->get('username')).',' .
' '.$db->namequote('userid').' = '.(int) $instance->get('id') .
' '.$db->namequote('session_id').' = '.$db->quote($session->getid())
);
$db->query();*/
// session object
$table = & jtable::getinstance('session');
$table->load( $session->getid() );
$table->guest = $instance->get('guest');
$table->username = $instance->get('username');
$table->userid = intval($instance->get('id'));
$table->usertype = $instance->get('usertype');
$table->gid = intval($instance->get('gid'));
$table->update();
// hit 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 email address in our system. please register.');
//echo "redirect 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);
}
}best regards,
david
is not possible?
Comments
Post a Comment