Hi!

Drupal 4.3.2/XTemplate

I'm trying to make logins/registrations usable without having to enable the login block. Putting a link to ?q=/user or to ?q=/user/login works, except that after logging in you end up at ?q=/user. How can I redirect back to the home page like when the login block is enabled. I've looked through user.module, but don't quite understand how/where $edit is being set. Is there another parameter I can pass with the link to indicate where they should redirect back to?

Thanks!

Comments

flevour’s picture

drupal uses drupal_goto function to redirect page. have a look through user.module searching for "drupal_goto" and see where it redirects to "user" ...
have fun.

patman’s picture

I understand how the drupal_goto function is being invoked, and I see how I could modify user.module to send them back to "node". I didn't ask the question correctly. What I'd like to do is redirect the user to the page they were on when they clicked the link to "user/login", which could be anywhere on the site. It seems I should be able to do this without hacking up user.module, but I'll be darned if I can figure out how...

dries’s picture

When the 'user/login' page's handler is invoked, you can save the referrer in the user session and reuse it after the user completed the form. You can also save the referrer using a hidden form element, but this will only work correctly when caching is disabled.

patman’s picture

What would be the recommended way of doing this? I'd hate to hack on user.module, as I like to stay fairly upgrade-proof. I'm still feeling my way around Drupal, but would it make sense to write a module that "wraps" user.module, and handles the referrer saving magic?

Thanks!

dries’s picture

My gut feeling says you want to save the referrer in a session variable. You update the variable for each GET operation, but not for POST operations. Then, you should be able to use the referrer variable after the user got logged in.

If this works, I would accept such patch for core. The reason is twofold:

  • We can use it elsewhere to redirect users to the page they came from instead of being dropped on a default page. For example, this is repeatedly requested here and enables many usability improvements.
  • We can remove the hidden destination field in the user login block -- which is likely to be buggy when caching is enabled.

Maybe open a feature request (or a bug report) for this so we don't forget about it.

patman’s picture

Stevo_0’s picture

i modified the drupal_goto function, so that it was

drupal_goto('user/'. $user->uid . '/orders');

which is a valid link, and now i get this error everwhere ;|

Call to undefined function user_access()

morisy’s picture

Has anyone found a more elegent solution for this problem? It looks like the patch ended up getting scrapped, though I think it would be a very useful one for a lot of drupal site maintainers...