2

I would like to get a list of every login of a user. I know I can get a certain user with craft.users() but as far as I have seen, I get data for lastLoginDate only.

Is there a way to get a complete list of all logins? Is this information even stored?

1 Answer 1

3

Craft only stores the most recent login date for users (i.e. the lastLoginDate). To get a list of all users and their last login date, you could do something like this:

{% set users = craft.users.can('accessCp').all() %}

<table>
    <tr>
        <th>Username</th>
        <th>Last login</th>
    </tr>
    {% for user in users %}
        <tr>
            <td>{{ user.username }}</td>
            <td>{{ user.lastLoginDate|default ? user.lastLoginDate|date('Y-m-d H:i:s') }}</td>
        </tr>
    {% endfor %}
</table>

If you need to retain a more comprehensive login history, as opposed to only the most recent login date, you could try the Audit plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.