After logging in from /user or /user/login, the page redirects to /user, which is results in "Access denied". Instead, when logging in from /user or /user/login you should be redirected to /user/"uid". Also, /user should redirect to /user/"uid" when logged in.

Marked as critical since users shouldn't see "Access denied" when logging in.

Comments

ChrisKennedy’s picture

Looks like "user/login shouldn't be accessible for logged in users" might have caused this problem. In particular, this segment:

@@ -900,6 +900,7 @@ function user_login($msg = '') {
     '#attributes' => array('tabindex' => '2'),
   );
   $form['submit'] = array('#type' => 'submit', '#value' => t('Log in'), '#weight' => 2, '#attributes' => array('tabindex' => '3'));
+  $form['#action'] = url('user');
   return $form;
 }

It doesn't appear that the uid can be included in that action since the user hasn't logged in yet.

ChrisKennedy’s picture

Sorry, "user/login shouldn't be accessible for logged in users" -> http://drupal.org/node/69985

chx’s picture

Status: Active » Reviewed & tested by the community
StatusFileSize
new1.4 KB

This is the simple fix for it. Note that the code alreasy present in the beginning of user_login to deal with the case when called after login. Cases tested: logging in from block when viewing a node (landed on the node), logging in from 'user' (landed on user/1), trying to access user/login when logged in (landed on user/1 again).

moshe weitzman’s picture

Status: Reviewed & tested by the community » Needs work

the whole point of making user/login inaccessible is that you could add that path to a menu and it would only show up for anon users. this patch reverted that. perhaps a better fix is to point the login form at some path other than user/login.

webernet’s picture

Status: Needs work » Fixed

Committed by Dries: http://drupal.org/node/88474

I can confirm that it fixes the "Access denied" issue.

chx’s picture

Status: Fixed » Needs review
StatusFileSize
new1.33 KB

So, you guys want a user/login which is accessible for anons only so you can add it to the menu?

chx’s picture

StatusFileSize
new1.76 KB

The access attribute for the menu item of 'user' is never consulted because there is a default task. On the other hand, the callback attribute of user/login is totally unnecessary, because it will happily fall back to the one given at user and if you do not give one for user then you won't get a user login callback at 'user' when anonymous. So, if you want, you can use this patch as well. It will drive people nuts, but noone understands menu system anyways, so it does not matter.

chx’s picture

I wasked about my last sentence: people here are the poor developers who need to understand user_menu and need to compile a [callback, callback arguments, access] package from two definitons... or this is my current understanding. Let' see whether the second patch works or not...

webernet’s picture

Either patch appears to work correctly.

Another review, and it should be RTBC.

webernet’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #6 is RTBC.

#7 works, but may make another bug more obvious (http://drupal.org/node/72674) - when a link to /user/login is in primary links, /user becomes inaccessible to anonymous users (/user/login is OK).

dries’s picture

Status: Reviewed & tested by the community » Needs work

Doing a redirect while building the menu? This looks like an ugly solution to me. Can't we chose not to add the menu item when $user->uid is set? I'm trying to understand why we add the menu item to begin with.

chx’s picture

I have been asked that the path user should provide the login form when anonymous and the view of current logged in user otherwise. I have been asked to make it so that if someone adds user/login to his menu then it disappear when logged in. If there is any other way to satisfy all these requirements, it escapes me.

Note that I redirect during hook_menu !$may_cache because this is the earliest stage when such a redirect is feasible.

Also note that the big menu rewrite will clean up this "default task links to parent" nightmare but at this stage attemtping to change the behaviour of the menu system is not the best solution.

moshe weitzman’s picture

@dries - the reason we need a 'user/' menu item is that we want to write links to 'view your user profile' from within a node or comment but not require php permissions to do so. in other words, a link which does not require knowing the current uid. already, it is impossible write a link to 'edit you user profile' without php access and thats a support problem on my sites and on drupal.org

chx’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new2 KB

This patch works, you can have a login link in your menu if you point that to user (user/login does not work because of http://drupal.org/node/72674 ) . This patch depends on http://drupal.org/node/88707 .

chx’s picture

Note that this also does a redirect while building the menu just an 'inner' redirect. I still can't find any solution not employing redirection.

Richard Archer’s picture

chx asked me to have a look at this issue.

I agree with chx and Moshe that this is a problem that should be addressed.

I also agree with Dries that this solution looks a little ugly.

But I can't immediately see a better way.

chx’s picture

So, we either commit #6 or commit http://drupal.org/node/88707 (which is needed anyways) plus #14.

drumm’s picture

Status: Reviewed & tested by the community » Needs work

I tried #14-
patching file modules/user/user.module
Hunk #1 FAILED at 690.
1 out of 2 hunks FAILED -- saving rejects to file modules/user/user.module.rej

I think the way to test this is to log in and go to '/user' and '/user/login' and see if there is any problem, but I couldn't find any with unpatched code.

chx’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new2.05 KB

Rerolled, added comments.

dries’s picture

What do you mean with 'without writing PHP code'? I think the code comment is quite fuzzy.

webernet’s picture

StatusFileSize
new2.2 KB

Updated the comment to be more clear.

chx’s picture

Per Drumm's request, this patch serves lets you create two menu items (primary links):

  1. This points to the login form, but should not appear when logged in.
  2. This points to the logged in user's profile.

If you say this is a feature request, I do not agree. This was possible but was broken by the bugfix committed earlier.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

webernet’s picture

Status: Fixed » Needs review
StatusFileSize
new2.06 KB

Whoops - looks like a couple lines of code weren't properly removed (two copies of user/login).

Patch removes them and does a little formatting cleanup of some nearby lines.

webernet’s picture

StatusFileSize
new1.12 KB

Same patch, minus the formatting fixes.

chx’s picture

Status: Needs review » Reviewed & tested by the community

Yup. (how come these lines were not removed? ? ? anyways, this ends our long and ugly journey, I hope)

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)