LogLogins Plugin Tutorial
I could tell you how many hours it takes to develop a MODX extra Transport Package complete with a build script, properties, multiple MODX elements, internationalized strings, error checks, and then fully test it, but you wouldn't believe me. If you use this extra and like it, please consider donating. The suggested donation for this extra is $10.00, but any amount you want to give is fine (really). For a one-time donation of $50.00 you can use all of my non-commercial extras with a clear conscience.
This extra logs user logins and logouts to the Manager Actions Log. It does so for both Manager and front-end logins and logouts.
Go to System | Package Management on the main menu in the MODX Manager and click on the "Download Extras" button. That will take you to the Revolution Repository (AKA Web Transport Facility). Put LogLogins in the search box and press Enter. Click on the "Download" button, and once the package is downloaded, click on the "Back to Package Manager" button. That should bring you back to your Package Management grid. Click on the "Install" button next to LogLogins in the grid. The LogLogins package should now be installed.
Enabling the LogLogins Plugin
When installed, the plugin is disabled. To enable it, edit the plugin, and on the main tab, uncheck the "Plugin Disabled" checkbox. Save the plugin.
Once LogLogins is installed it will automatically record user logins and logouts to the Manager Actions Log for both Manager and front-end logins. It will report the time, the username, and the context(s) involved.
To see the report, go to Reports | Manager Actions on the MODX Manager Top Menu. The Manager Actions log can be filtered by user, action, or time, but as far as I can tell, there's no way to show just logins and logouts at the same time.
If any users are logged in (including you) when you install LogLogins, their first logout will not report the context(s) correctly.
LogLogins records the context(s) in a User Setting (
loglogins_contexts) for each user. This is done automatically and there's never any need to edit the User Setting. Doing so will have no effect other than to change the context(s) reported on logout, and then only if the user is logged in when the change is made.
LogLogins will only log the event if the the correct System Event is invoked when the user logs in or out. The Login snippet and the Manager login page both do this correctly, but if the user is logged in or out in code that doesn't invoke the appropriate event or doesn't invoke it properly, the login or logout may not be recorded.
The context(s) reported in the log for front-end logins and logouts are the values in the Login snippet's
&contexts property. If they are misspelled or are not real contexts, they will still be reported, even though the user isn't really logged in to them. I tried testing them to see if the user is really logged in to each context, but unfortunately
$user->hasSessionContext() always returns
true as long as they're listed in the Login snippet's
If a user closes the browser window without formally logging out, the logout will not be logged, even though that action usually logs the user out.
If you have the book and would like to download the code, you can find it here.
If you have the book and would like to see the updates and corrections page, you can find it here.
MODX: The Official Guide is 772 pages long and goes far beyond this web site in explaining beginning and advanced MODX techniques. It includes detailed information on:
- Installing MODX
- How MODX Works
- Working with MODX resources and Elements
- Using Git with MODX
- Using common MODX add-on components like SPForm, Login, getResources, and FormIt
- MODX security Permissions
- Customizing the MODX Manager
- Using Form Customization
- Creating Transport Packages
- MODX and xPDO object methods
- MODX System Events
- Using PHP with MODX
Go here for more information about the book.
Thank you for visiting BobsGuides.com
— Bob Ray