I configured login destination to use PHP snippets to determine the final url. The idea was that the user would log in and then a php snippet would check that user's information to determine where to send them. This worked fine in 6.x.2.5

Upon updating to 6.x.2.6 the order in which events happened changed critically. It now executes the Destination URL PHP snippet before the user is actually logged in, meaning my snippet no longer has access to any useful data.

I changed the snippet to be:

global $user;
die (print_r($user, TRUE));

And as you can see, the user is not logged in upon reaching this code block.

stdClass Object ( [uid] => 0 [hostname] => REDACTED [roles] => Array ( [1] => anonymous user ) [session] => [cache] => 0 ) 

Comments

jbiechele’s picture

subscribe

Jaypan’s picture

I am seeing the same behavior. I downgraded to 2.5 for the time being.

3CWebDev’s picture

Same issue. Downgrading and subscribing.

spuky’s picture

Title: Order of execution has changed. (PHP snippets before actual login) » Order of execution has changed. (PHP snippets before actual login)
Priority: Normal » Critical

Set to critical to make it easyer to spot... took me quite some time to find what was wrong...

Downgraded to 2.5

mikesir87’s picture

Having the same issue here... It actually broke the site because we're using Content Profile and Auto Assign Role during registration. With the PHP firing beforehand, the profiles aren't being saved. Downgraded and subscribing.

gownikarunakar’s picture

Anyone has found any solution for this yet?

Sohodojo Jim’s picture

Same here. Downgraded and subscribing.

3CWebDev’s picture

Component: Miscellaneous » Code

Okay, I tracked down the cause of the bug. The latest version has a new form_alter hook on the user_login form that appears to be clashing with the hook_user hook. I can't tell the purpose of the new form_alter hook but it is also calling the routine that evaluates the PHP snippet and redirecting the user before the hook_user hook is doing it.

I found a work around that I think is allowed because of another bug. If you check the "Return user to where he/she came from. (Preserve destination" box in the "destination URL admin" section it will bypass the user_login hook, run the PHP evaluation and then redirect as it did in the previous release.

Please see comments in the culprit function from the 6.2.6 version below.

function login_destination_form_alter(&$form, $form_state, $form_id) {
// THIS FUNCTION IS NEW AND BEING CALLED BEFORE HOOK_USER
  if ($form_id == 'user_login') {
    
    if ( variable_get('ld_destination', TRUE) ) {
     // THIS FUNCTION IS EMPTY AND DOES NOT DO ANYTHING - BUT BY SELECTING "Return user to where he/she came from. (Preserve destination)" THIS SECTION WILL RUN INSTEAD OF THE FOLLOWING

    }
    // php snippet or static url
    else {
      // THIS IS THE ACTUAL CAUSE OF THE PROBLEM AS IT RUNS BEFORE THE USER OBJECT IS LOADED AND DOES NOT ALLOW FOR PROPER FUNCTION PHP SNIPPETS FOR REDIRECTS
      $arr = login_destination_calculate_redirection_path_and_query($form);
      $path  = $arr[0];
      $query = $arr[1];
      if (!empty($query) ) {$add_to_path = "?" . $query;}
      $url = $path  . $add_to_path;
    }
  

    $form['#redirect'] = $url;
  }
}

3CWebDev’s picture

Assigned: Unassigned » 3CWebDev
3CWebDev’s picture

Status: Active » Fixed

This has been fixed in the latest module. Please install and test. Please be aware the the redirect conditions are also working now and if you had conditions already entered they may not have been working on previous versions and will begin working on the new version. This could cause unexpected actions.

Status: Fixed » Closed (fixed)

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

rsvelko’s picture

Issue summary: View changes

I confirm that it works now. The php snippet has access to the username and roles etc...