If a user clicks the one-time login link (from new password request) and someone is logged into the drupal site on the browser they're using, they get a message that says "You have already used this one-time login link. It is not necessary to use this link to login anymore. You are already logged in.". The reality is that we don't know whether they've used the link, just that *someone* is logged in.

How to recreate: Get a one-time login link. Log in with your username and password (or with a different account's username and password). Click the link.

What I expect: To get a relevant message (You're already logged in... Someone is already logged in...)

What happened instead: You get the error message "You have already used this one-time login link. It is not necessary to use this link to login anymore. You are already logged in." Note that you get this message regardless of whether the link was used, and regardless of what user was logged in.

The attached patch fine-tunes this behavior with better error message and it differentiates the message (whether the logged-in user is the user who clicked the link or not).

Comments

rfay’s picture

StatusFileSize
new1.17 KB

@greggles was kind enough to take a look at this. Here is a rerolled patch with his suggestions, which are formatting, comment style, etc.

rfay’s picture

Version: 6.13 » 7.x-dev
Status: Active » Needs review
Issue tags: +#d7ux
StatusFileSize
new1.17 KB

It's my understanding that patches like this have to make it into D7 first, so here it is for D7.

rfay’s picture

Here are screenshots of the behavior:

Note that the "other user logged in" behavior of the existing code is probably the most pernicious... It says "you are already logged in" and you most certainly are not. But the "this user logged in" behavior is also bad. On Drupal sites people are often logged in without understanding that they are, and they get all confused when they use a link and it says they've already used it, etc.

--------------------------------------------------------
Only local images are allowed.
--------------------------------------------------------

Only local images are allowed.

--------------------------------------------------------
Only local images are allowed.

rfay’s picture

StatusFileSize
new5.44 KB

Per conversation with @Bohjan, I changed the text for when a user is already logged. It seems we don't really need to tell them they didn't need the one-time-link. We just need to get them to change their password so they know how to use the system. The new text for when a user uses the link but the same user is already logged in:

You are logged in as username. (link to user/xxx/edit) Change your password.

Here's the resultant screenshot for the case where the user was already logged in.
Only local images are allowed.

rfay’s picture

StatusFileSize
new1.19 KB

Oops - forgot the patch for #5. Here it is.

Bojhan’s picture

Looks good, I expect it will take some time before this gets a second review - with code freeze and all

robloach’s picture

StatusFileSize
new1.41 KB

Refactored a bit, fixed some coding convention and added some little documentation, the functionality is the same. Even though the use case is a bit strange, I think its need is valid.

Another thing we could do is use:

  if ($user->uid) {
    $message = $user->uid == $uid ? "You are logged in as %user. <a href='!link'>Change your password.</a>" : "Someone else is already logged into the site on this computer. Please <a href='!link'>logout</a> and try using the link again.";
    drupal_set_message($message, array('%user' => $user->name, '!link' => url("user/{$user->uid}/edit"))); 
    drupal_goto();
  }

...But that doesn't really look pretty.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

big improvement. i think thats pretty (informative).

webchick’s picture

Status: Reviewed & tested by the community » Needs work
+++ modules/user/user.pages.inc	17 Aug 2009 22:47:05 -0000
@@ -78,9 +78,17 @@
+      drupal_set_message(t("You are logged in as %user. <a href='!link'>Change your password.</a>", array('%user' => $user->name, '!link' => url("user/{$user->uid}/edit"))));
...
+      drupal_set_message(t("Someone else is already logged into the site on this computer. Please <a href='!link'>logout</a> and try using the link again.", array('!link' => url('logout'))));

These t() strings are a bit inconsistent with others in core:

a) We should switch the quotes so that the string is encased in single quotes and the link href in double quotes.

b) Elsewhere, url() strings are passed in with descriptive @ placeholders that describe where they're going to go, rather than ! placeholders called a generic "link". For example, @block-admin, @cron, etc.

c) The braces in user/{$user->uid}/edit is rather ugly. Does it work without? If not, let's use concatenation here instead as it helps with the readability.

Finally, that second string doesn't quite feel right. I like that it's plain-English, but it doesn't actually tell me enough to figure out what's going on. Does my browser have an active session as another user? Or is my cookie invalid? Or..?

Maybe something instead like "You are currently logged in as $this_user->name but have used a password reset link for $other_user->name. Please log out and try again."

I'm on crack. Are you, too?

rfay’s picture

Status: Needs work » Needs review
StatusFileSize
new1.68 KB

This patch addresses the issues raised in #9. It also catches the odd case of a reset link for an unknown user, which would have caused a bad error message given that we now try to load the user whose reset link we clicked.

rfay’s picture

StatusFileSize
new1.69 KB

Here's a re-roll with a couple of tiny cosmetic changes (added a period at the end of the drupal_set_message(), changed placeholder to '%' from '@').

TheRec’s picture

The patch is working great. I mark this RTBC looking at the previous feedbacks and because I tested this extensively.

On a side note, and out of the scope of this patch, I've discovered another bug that we should investiagte, when you try to reach a reset link that does not exist and you are not logged in, you get an access denied page (which is good) but it's repeated two times (this must be related to the way drupal_access_denied() is used). This will surely be reported in another issue but I need to further test it (with other call to drupal_access_denied()).

TheRec’s picture

Status: Needs review » Reviewed & tested by the community
webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD. Thanks!

Status: Fixed » Closed (fixed)

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

rfay’s picture

Version: 7.x-dev » 6.x-dev
Status: Closed (fixed) » Patch (to be ported)

IMO, this should be ported to D6 as the same problem exists there. I know there is the issue of string-freeze, but this is a good candidate for an exception.

albert volkman’s picture

StatusFileSize
new1.79 KB

D6 backport.

albert volkman’s picture

Status: Patch (to be ported) » Needs review

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.