J! 1.0.13 Login and Logout 'logging' Question

Have a programming question regarding your component, plug-in, extension or core hacks? Have an interesting tidbit, FAQ or programming tip you’d like to share? This is the place for you.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Post Reply
User avatar
edward_cox
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Thu Aug 30, 2007 3:05 am

J! 1.0.13 Login and Logout 'logging' Question

Post by edward_cox » Tue Jan 22, 2008 10:44 pm

Hello All,

I need to be able to record the Date/Time that a registered user logs in and out of Joomla (along with some other details such as Name). I know that there is a field 'lastvisitDate' that effectively is the login Date/Time, but I need to trap the logout Date/Time as well.

Can someone please tell me, apart from attempting to write a Mambot/Plugin which doesn't seem to support the events, where in the core code I can insert some code to write these details to a new table?

Can someone please clarify for Joomla 1.0.13 if Mambots support any 'onuserlogin' or 'onuserlogout' USER events?

Thank you in anticipation,

Ed Cox

User avatar
scarney
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Sun Oct 23, 2005 11:48 pm
Contact:

Re: J! 1.0.13 Login and Logout 'logging' Question

Post by scarney » Thu Jan 24, 2008 12:49 am

I just came to the forum tonight looking for the same thing.  Actually I would be very happy if there was a module or component that already did this. Or, if somebody could point me to where in the system joomla writes logs for who is logging in and logging out!

Thanks,  Sean Carney

User avatar
edward_cox
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Thu Aug 30, 2007 3:05 am

Re: J! 1.0.13 Login and Logout 'logging' Question

Post by edward_cox » Fri Jan 25, 2008 1:58 am

Hi Sean,

as I had to get this done in a rush I ended up with a hack solution. The Community Builder (CB) comprofiler.php code was my answer and specifically allowed me to trap a user login and logout (except for a session timeout) writing the data to a new table.
If it's of any use to you I would be happy to share the hacked code (all care, no responsibility and all that). Just let me know.

in a nutshell:
I added a new table: jos_users_access
fields : id, userid, logdate, name, branch, login, logout, event
(your mileage may vary - please modify to suit)

within

Code: Select all

 function login()


directly before

Code: Select all

$_PLUGINS->trigger( 'onAfterLogin', array($row, true));


Code: Select all

$com_query = "SELECT cb_location FROM #__comprofiler WHERE id = ".$row->id;
         $database->setQuery($com_query);
         $where = $database->loadResult();

         $logdate = date('y/m/d g:i:s');
              $xzquery = "INSERT INTO #__users_access SET userid = '$row->id', logdate = '$logdate', name = '$row->name', branch = '$where', login = '$logdate', logout = '', event = 'login'";
              $database->setquery($xzquery);
              $database->query();


This ensures that the 'login' Event is trapped directly onAfterLogin via the event system.

Then for the logout code:

Directly before

Code: Select all

$mainframe->logout();
is called.. ..

Code: Select all

$com_query = "SELECT cb_location FROM #__comprofiler WHERE id = ".$my->id;
        $_CB_database->setQuery($com_query);
        $where = $_CB_database->loadResult();

   $logdate = date('y/m/d g:i:s');
   $query = "INSERT INTO #__users_access SET userid = '$row->id', logdate = '$logdate', name = '$row->name', branch = '$where', login = '', logout = '$logdate', event = 'logout'";
   $_CB_database->setquery($query);
   $_CB_database->query();


Which ensures the logout data is trapped before all the data is lost.

Anyway, it's a hack - and I would much prefer that this was a Mambot/Module Extension/Plugin.

Hope that's of some assistance. (and thanks to those that were able to assist me!)

Regards,

Ed Cox

User avatar
scarney
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Sun Oct 23, 2005 11:48 pm
Contact:

Re: J! 1.0.13 Login and Logout 'logging' Question

Post by scarney » Fri Jan 25, 2008 3:14 am

Hi Ed,

That looks great.  Unfortunately I am not literate enough to know how to do that.  But, it looks nice.  I sure wish somebody had a module already.  :-)


I will consider this more but don't think I will be brave enough to try it. :-)

Sean


Post Reply