Where to add custom code that runs on user login & logout

Discuss about Group-Office development here

Moderator: Developers

User avatar
Mr.Magoo
Posts: 38
Joined: Thu May 14, 2009 5:45 pm

Where to add custom code that runs on user login & logout

Postby Mr.Magoo » Mon Aug 24, 2009 7:57 am

People,

I'd like to execute some custom PHP code when a user logs in to GO3.

I'd like to execute some other PHP code when a user logs out again.

Here's the $64,000 dollar question: where do I add my code?

BTW, I'm using version 3.01-stable-34.

Anyone?

TIA
Mr. Magoo
"People, let's do it to them, before they do it to us!”
...Hillstreet Blues
mschering
Site Admin
Site Admin
Posts: 8333
Joined: Tue Apr 20, 2004 1:06 pm
Location: The Netherlands - Den Bosch
Contact:

Re: Where to add custom code that runs on user login & logout

Postby mschering » Mon Aug 24, 2009 10:33 am

Best regards,

Merijn Schering
Intermesh
User avatar
Mr.Magoo
Posts: 38
Joined: Thu May 14, 2009 5:45 pm

Re: Where to add custom code that runs on user login & logout

Postby Mr.Magoo » Mon Aug 24, 2009 1:24 pm

Yep, I'm sure I could.

But for my purposes, it's overkill to create a new class in a new module with new event-listeners and the
whole shebang that comes with it.
I'm working on a proof-of-concept and might do this later on, when the effort is warranted by the proof.
Until then, I just want to add some extra code to an existing module / class / script that handles those
two events anyways.
Now don't tell that they aren't there, because we all have to log in and log out, don't we?
"People, let's do it to them, before they do it to us!”
...Hillstreet Blues
mschering
Site Admin
Site Admin
Posts: 8333
Joined: Tue Apr 20, 2004 1:06 pm
Location: The Netherlands - Den Bosch
Contact:

Re: Where to add custom code that runs on user login & logout

Postby mschering » Tue Aug 25, 2009 7:13 am

It's not much shebang. Just create two folders and one file:

modules/mymodule/classes/mymodule.class.inc.php

in mymodule.class.inc.php:

Code: Select all

class mymodule
{

	public function __on_load_listeners($events){
		$events->add_listener('login', __FILE__, 'mymodule', 'login');
		$events->add_listener('logout, __FILE__, 'mymodule', 'add_user');
	}

	public function  login($username, $password, $user){
		//do something here on login
	} 

	public function  logout($destroyed_session){
		//do something here on logout
	}
} 

I've updated the wiki with this better example too:
http://www.group-office.com/wiki/Event_ ... _listeners
Best regards,

Merijn Schering
Intermesh
User avatar
Mr.Magoo
Posts: 38
Joined: Thu May 14, 2009 5:45 pm

Re: Where to add custom code that runs on user login & logout

Postby Mr.Magoo » Tue Aug 25, 2009 11:20 am

I already printed out the article discussing event handlers, and certainly appreciate your efforts for making this clear to me.
Thanks for that. But like I said, at the moment I have very limited time and need to develop a proof of concept.
Once I've got my point across, I have more time to spent on development. Simply a matter of time and resources.
Therefor, you could have just as easily pointed me to the following segment of code in action.php in the GO3 root:

Code: Select all

    case 'login':
    ...
    ...
    ...
    $response['success']=true;
    ... <= insert code
    break;
Just hook in your code were it says to above, and it wil execute on a user login. Did the job for me just fine.
I agree that your solution is the way to go -- my approach is just a quick and dirty way to test if something works.

Mr. Magoo
"People, let's do it to them, before they do it to us!”
...Hillstreet Blues

Who is online

Users browsing this forum: No registered users and 1 guest