Add logout history

Created on 15 March 2022, over 2 years ago
Updated 24 June 2024, 1 day ago

Problem/Motivation

Currently login history records the login time. It would be handy to also log the logout time for each session to provide a more complete history.

Steps to reproduce

Proposed resolution

Add the fields Session ID and Logout timestamp to the login_history table.

Remaining tasks

Provide the code for review.

User interface changes

API changes

Data model changes

Feature request
Status

Needs review

Version

2.0

Component

Code

Created by

🇦🇺Australia imclean Tasmania

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇪Germany Svitlana

    I tested it and sadly don't see the data in logout field.

  • 🇵🇹Portugal jcnventura

    As a new feature, this is only for the 2.x branch.

  • Status changed to Needs review over 1 year ago
  • 🇦🇺Australia imclean Tasmania

    @Svitlana, did you run update.php and clear the cache? Which patch did you use, or did you use the MR?

  • Status changed to Needs work over 1 year ago
  • 🇵🇹Portugal jcnventura

    Doesn't really matter which version @Svitlana tested. The logout time needs to be added as well to the config/install/views.view.login_history.yml. And hook_update_8004 needs to change that view for existing installs to add the new column.

    The existing MR probably works fine on 1.x, but 1.x will not get any new features.

  • Status changed to Needs review over 1 year ago
  • 🇦🇺Australia imclean Tasmania
  • Status changed to Needs work over 1 year ago
  • 🇦🇺Australia imclean Tasmania

    hook_update_8004 needs to change that view for existing installs to add the new column.

  • Status changed to Needs review over 1 year ago
  • 🇦🇺Australia imclean Tasmania
  • 🇮🇳India Prashant.c Dharamshala

    Re-rolled patch

  • 🇦🇺Australia imclean Tasmania

    @Prashant.c, patches should go against dev. Your reroll reorders some things, adds whitespaces and removes a newline at the end of a file. It'd be helpful if you could explain the reroll and provide an interdiff.

  • 🇮🇳India Nikhil_110

    I applied the patch on my local machine using Drupal 9.5 with login history v2.x-dev. It is not working properly..when user is logout he does not see the data in logout field. Because when user logout session is destroyed and session id is different.

    $current_time = \Drupal::time()->getRequestTime();
      <strong>// Get current session ID and hash it.
      $sid = Crypt::hashBase64(\Drupal::service('session')->getId());</strong>
      \Drupal::database()->update('login_history')
        ->fields([
          'logout' => $current_time,
        ])
        ->condition('sid', $sid, '=')
        ->execute();

    So this code is not working properly.
    I have added the test steps and Attaching the screenshot for reference.Please review.

    Test Step -

    • Setup Drupal with login history v2.x-dev
    • Enabled login history module
    • Apply patch #17 - https://www.drupal.org/project/login_history/issues/3269753#comment-1490... Add logout history Needs review
    • Run update.php and clear the cache
    • Go to Admin > Reports > Login history
  • 🇦🇺Australia imclean Tasmania

    @Nikhil_110, why did you use the patch in #17? Try #19 instead.

  • 🇮🇳India Prashant.c Dharamshala
Production build 0.69.0 2024