michael-milette / moodle-filter_filtercodes

FilterCodes filter for Moodle enables content creators to easily customize and personalize course and site content using plain text tags (no HTML). For premium support, contact us at https://www.tngconsulting.ca/contact
https://moodle.org/plugins/filter_filtercodes
GNU General Public License v3.0
32 stars 45 forks source link

Add new last login date filter code #200

Closed alexmorrisnz closed 2 years ago

alexmorrisnz commented 2 years ago

Hi @michael-milette this PR adds a new last login date filter code. I've tested this on Moodle 3.9

michael-milette commented 2 years ago

Hi @alexmorrisnz , thank you for your contribution. Your code looks great.

I've actually written code almost identical to yours in the past but never included it in FilterCodes because I did not see the point once I realized what date/time was being returned.

The problem is, I would expect such a tag to show me my previous login date. However, the moment you login, the date gets updated in the user's record. As a result, it actually shows you the date and time at which you just logged in for your current session. To show the previous login date/time, I suspect the only way would be to query the Moodle log.

Could you please provide a use case for your code as is at the moment? I just need your help to understand why someone would need to know how long it has been since they started their current session.

Best regards,

Michael

alexmorrisnz commented 2 years ago

Hi @michael-milette,

I looked into this and found this code: https://github.com/moodle/moodle/blob/master/lib/moodlelib.php#L3393 It sets the last login value to the currentlogin (previous at this point) time, then updates the currentlogin value to be the new login timestamp. The currentlogin field is storing the current sessions login time.

We're using this to show the previous login timestamp to users after they log-in so they may recognise the value as being more recent than when they last logged in, in an attempt for users to self identity account takeovers.

I've tested this on Moodle 3.9 and can confirm that after logging in the lastlogin value is set to the previous logins timestamp, not the current logins timestamp.

Thanks

michael-milette commented 2 years ago

Hi @alexmorrisnz ,

Thank you very much. Everything was perfect and the new tag has been integrated and tested. Thank you for your contribution!

IMPORTANT: Please note that the tag has since been renamed from {lastlogindate} to simply {lastlogin}.

This change is currently only available from the version of FilterCodes here on GitHub and will be made available on Moodle.org/plugins around the same time as Moodle 4.0 is launched (but it will still be backwards compatible).

Let me know if you have any questions or concerns.

Thanks again for your fine contribution!

Best regards,

Michael