On Sat, Jul 3, 2010 at 9:21 AM, K. Ono
Erm, you can use the system and user plugin system for precisely this purpose.
For example I have a combination of System and User plugins that will grab the Windows userid[using IIS directory protections], creates the Joomla user if it does not exist, and logs the user on as that user.
The confusion here might have come from the fact that you have to use BOTH system and User plugins for this function.
For the system plugin, you use the onAfterInitialize event:
$application = JFactory::getApplication();
$user =& JFactory::getUser();
$plugin = & JPluginHelper :: getPlugin('system', 'myplugin');
$params = new JParameter($plugin->params);
// Set a parameter here so you can test on the frontend but don't
// use your plugin in the backend until you
// are sure it owrks
if(!$params->get('backend',0)) {
if($application->isAdmin()) return false;
}
// now you may want to load some information
// about your username somehow....not sure where your getting/setting user info from
// loaded into $username
// if this user is already logged on, we don't need to do it again
if ($user->username == $username) {
return false;
}
// if autocreate is set, create unknown users
if($params->get('autocreate',0)) {
// lookup user by name
$finduser =& JFactory::getUser($username);
// if this user does not exist, create it
if !($finduser) {
jimport('joomla.user.user');
$newuser =& JUser::getInstance(0);
// full name, domain + name
$newuser->setParameter('name',$userinfo);
// username
$newuser->setParameter('username',$username);
// set normal reg user
$newuser->setParameter('type','Registered');
$newuser->setParameter('gid',18);
// set password to users full info
$newuser->password = $userinfo;
$newuser->save();
}
}
$user =& JUser::getInstance(0);
// if user A is logged on to Joomla, but user B is on the alternate system
// if override is set, user A is logged out and B is logged in
if(!$params->get('override',0)) {
if($user->id) return false;
} else {
if($user->id) {
$mainframe->logout();
}
}
// Ok, so we're all done doing some pre-loading stuff...the user is not
// already logged on to Joomla
// so......log the user on
$ret = $mainframe->login(array('username' => $username));
return $ret;
At this point, you need a authentication plugin as well to capture your login credentials and go ahead and approve the user's logon by verifying your system.
Note: this code here has a few oddities in[weird error messages]....I fixed the code up on the system, but don't have access to it at the moment.