Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Some useful features might be:
- Statistics on logins per day/week/year
- Filterable by role etc.
- Sorting / grouping by count, most logins etc.
- Some sort of views integration
Thanks
Comment | File | Size | Author |
---|---|---|---|
#3 | login_history-1402266-3.patch | 26.23 KB | star-szr |
#2 | login_history-1402266-2.patch | 0 bytes | star-szr |
Comments
Comment #1
bocaj CreditAttribution: bocaj commentedThis is a good idea as well. Let me get #1400672: Provide Tokens for [user:past-login] (and more?) figured out first and then I will look into these items.
Thanks for the suggestions!
Comment #2
star-szrHere's a patch to get things rolling on Views integration. I wanted to be able to export login data via Views data export. This is my first attempt at integrating a module with Views so I'm sure there's room for improvement.
Note: the patch at #1691474: Convert files to unix line endings to convert the line endings to Unix should be applied first or this patch will probably not apply cleanly. I couldn't easily find a way around this. You can try applying the patch with "git apply --index login_history-1402266-3.patch" but you will probably still see warnings about whitespace errors.
The patch allows for creating a view of type "User login records", and defines two default views (disabled by default) which are very similar to the default reports provided by Login History. When enabled, these default views will override the reports provided by Login History. The default views can be overridden to add exposed filters etc. or new views can be created. I'm not sure how to replicate the "View own login history" permission via Views (other than creating a separate page with a different path), so the default per-user report just uses the "View all login histories" permission.
If you're creating your own view of User login records from scratch you'll probably want to add the "Login History: User" relationship to be able to pull in information about the user.
I'm still not sure how to create a view to list i.e. number of logins per user in the past 3 months. I think that would involve creating a view of users, then adding the Login History relationship, but I think more views integration code would be needed to provide the number of logins to that view. I've yet to find another contrib module that serves as a good example of this type of functionality.
Comment #3
star-szrOops, here's the patch.
Comment #4
star-szrI'm thinking this can be accomplished with Views aggregation.
Comment #5
star-szrShamefully unassigning, I haven't touched this since January.
Comment #6
mouhammed CreditAttribution: mouhammed commentedI've created a custom module to allow you to use user records from views. Here the link on my sandbox. login_history_views
Comment #7
star-szrHere is the outside link: https://www.drupal.org/sandbox/mouhammed/2396263
This doesn't seem to get things any further than my patch, namely aggregation. For what it's worth #3 still applies cleanly to 7.x-1.x.
Comment #8
sanjarhakimi CreditAttribution: sanjarhakimi commentedWill this allow me to have a View field to simply display "Last Login" (previous login) ?
Comment #9
star-szr@sandshakimi it's been a while since I've looked at this but I'm pretty sure with the patch that is possible :)
Comment #10
Alex Bukach CreditAttribution: Alex Bukach at This Little Duck commentedThe patch #3 works fine for me on several projects.
Comment #11
bsarchive CreditAttribution: bsarchive as a volunteer commentedI've applied the patch but I'm not getting the User Login Records type coming up in Views. I've cleared all the caches (including Views) and disabled/re-enabled the login history module.
Any ideas?
Thanks,
Ben
Comment #12
Alex Bukach CreditAttribution: Alex Bukach commentedTry reverting the view.
Comment #13
bsarchive CreditAttribution: bsarchive as a volunteer commentedSorry, how do I do that?
Comment #15
gregglesI just tested this out and it worked for me aside from the change for #1707200: Change user login history menu item to use a dash instead of an underscore. I fixed that and committed/pushed the patch.
Thanks, @Cottser.
@bsarchive: did you "enable" the view? Be sure to enable the Views UI module and then go to admin/structure/views and look for the "User login history" view and enable it.
There is an issue for 8.x at #2727711: Views integration? so I'm not going to move this to "needs to be ported" status.
I think this addresses most of the major issues, so I'm re-titling and marking this fixed. As people work with this we could consider adding more reporting to the module, but...I'm not sure how much sense that makes. Reporting is the kind of thing that's hard to get right and easy to spend a lot of time building. I would guess a different "BI" type of tool that is hooked up to the Drupal database might be a better general solution for anything that can't be handled by Views or a Views reporting plugin.