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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bocaj’s picture

Status: Active » Postponed

This 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!

star-szr’s picture

Status: Postponed » Needs review
FileSize
0 bytes

Here'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.

star-szr’s picture

Oops, here's the patch.

star-szr’s picture

Assigned: Unassigned » star-szr

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.

I'm thinking this can be accomplished with Views aggregation.

star-szr’s picture

Assigned: star-szr » Unassigned

Shamefully unassigning, I haven't touched this since January.

mouhammed’s picture

Issue summary: View changes

I've created a custom module to allow you to use user records from views. Here the link on my sandbox. login_history_views

star-szr’s picture

Here 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.

sanjarhakimi’s picture

Will this allow me to have a View field to simply display "Last Login" (previous login) ?

star-szr’s picture

@sandshakimi it's been a while since I've looked at this but I'm pretty sure with the patch that is possible :)

Alex Bukach’s picture

The patch #3 works fine for me on several projects.

bsarchive’s picture

I'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

Alex Bukach’s picture

Try reverting the view.

bsarchive’s picture

Sorry, how do I do that?

  • greggles committed e2aa8fe on 7.x-1.x authored by Cottser
    Issue #1402266 by Cottser, Alex Bukach: Statistics and maybe views...
greggles’s picture

Title: Statistics and maybe views integration » Login History Views integration
Status: Needs review » Fixed

I 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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.