umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
MIT License
4.48k stars 2.69k forks source link

User - First ever "Last login" time is recorded or display in the wrong timezone. #14612

Closed TFAstudio closed 1 year ago

TFAstudio commented 1 year ago

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

10.6.1

Bug summary

The 1st back-office login by any new Umbraco User does not accurately reflect the local time of that user's device nor that of the hosting environment. The "Last login:" is wrong.

image

Specifics

Wrong time is displayed. Out by -10 hours here in Australia. So perhaps it is writing as UTC or GMT instead of local.

Note: Subsequent logins show the correct time.

Steps to reproduce

  1. Invite a new user.
  2. Log in as that user (once) to the back-office.
  3. Head to Users in the back-office and observe the "Last login" time for that new user.
  4. Log out the new user, and log in again.
  5. Head to Users in the back-office and observe the "Last login" time for that new user which is now displayed correctly.

Expected result / actual result

The Last login time should always be accurate.

First login: image

2nd login immediately afterwards: image

github-actions[bot] commented 1 year ago

Hi there @TFAstudio!

Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.

We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.

We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.

Thanks, from your friendly Umbraco GitHub bot :robot: :slightly_smiling_face:

miguelcrpinto commented 1 year ago

I was able to reproduce the issue in V12.0.0

bergmania commented 1 year ago

Hi thanks for reporting and confirmation. I have a hard time reproducing, but maybe it's because my server is in same timezone as my user. Did you reproduce with a local server or only on hosting?

miguelcrpinto commented 1 year ago

@bergmania I reproduced it locally. The issue is that in the PostSetInvitedUserPassword method of the CurrentUserController the LastLoginDate is being assigned the DateTime.UtcNow. From what I've seen in the CMS code, the LastLoginDate is always assigned the local time and not UTC.

I'll try to fix this later today and create a PR.

@bergmania do you know why is the user being saved using the _userService.Save instead of _backOfficeUserManager.UpdateAsync? Is there any specific reason for this? or can I replace?

bergmania commented 1 year ago

@bergmania do you know why is the user being saved using the _userService.Save instead of _backOfficeUserManager.UpdateAsync? Is there any specific reason for this? or can I replace?

No, I don't know why it uses _userService here. For the upcoming v14, we have managed to hide all the knowledge of the user stores, so all interaction have to be through the service.

miguelcrpinto commented 1 year ago

@bergmania ok, I'll try to fix this by assigning the DateTime.UtcNow to LastLoginDateUtc and save the user via _backOfficeUserManager.UpdateAsync

miguelcrpinto commented 1 year ago

Created PR 14619 to fix this issue.

@bergmania I tried to keep the changes to a minimum but I suggested an improvement in the PR description. Please check and let me know if I should apply it.

nul800sebastiaan commented 1 year ago

Fixed in https://github.com/umbraco/Umbraco-CMS/pull/14619