Add onBeforeInitialise event to the JApplication class

53 views
Skip to first unread message

K. Ono

unread,
Jul 3, 2010, 9:21:00 AM7/3/10
to joomla-dev...@googlegroups.com
Hi,

Regarding Joomla 1.6, could you consider adding the
'onBeforeInitialise' event to the initialize() method of the
JApplication class?

My web application that I am trying to integrate with Joomla has its
own pluggable authentication system so that it needs to be able to
initialize the current user object before the Joomla core does. I was
able to integrate it with WordPress without any hack but could not
find a way in Joomla so far unless adding the event to the core.
I am currently using 1.6.0b3

What do you think?

I couldn't get any responses at joomla.org forum, so I am reposting
the same topic here.
I am pretty new to Joomla! so am sorry if this isn't the right way in
the Jooma developers community...

thanks

Hannes Papenberg

unread,
Jul 3, 2010, 9:33:10 AM7/3/10
to joomla-dev...@googlegroups.com
The issue is, that before the onAfterInitialise event, there is in fact
no code that could fire the plugins.

Couldn't you just replace the variable in JFactory that holds the user
object?

Hannes

Gary Mort

unread,
Jul 5, 2010, 12:21:10 PM7/5/10
to joomla-dev...@googlegroups.com
On Sat, Jul 3, 2010 at 9:21 AM, K. Ono <ono...@gmail.com> wrote:
Hi,



My web application that I am trying to integrate with Joomla has its
own pluggable authentication system so that it needs to be able to
initialize the current user object before the Joomla core does.

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 email to user...@stvinc.com
$newuser->setParameter('username',$username.'@stvinc.com');
// 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.
Reply all
Reply to author
Forward
0 new messages