I am midstream on a migration from drupal 7 and have run into a problem.

I am have been required to use the universities shibboleth server to permit access to the backdrop site, and within a 'go there first after shib' module I am writing, I am using the shib session's variable's email value to check if a user exists and, if not, create one.  That part works fine.

The issue I have run into is that within this module once I log the user in (which they are not at that point) using user_login_finalize(), (which seems to work fine) the function backdrop_goto no longer works.    (it works just fine before that statement, and if it is commented out, as below.)

I am hoping that there is an appropriate approach around this, I am at a loss. 

I have included a section of my clumsy code in case it helps.

$found_user = FALSE;

if (array_key_exists ( 'mail', $_SERVER )){

  $this_email = $_SERVER['mail'];

  $found_user = user_load_by_name($this_email);

} else {

  backdrop_goto( 'login-issue' );   /// this works!!

}

if ($found_user == FALSE) { // need to create a new user

 $new_user = array(

   'name' => $this_email,

   'pass' => NULL, // note: do not md5 the password

   'mail' => $this_email,

   'status' => 1,

   'init' => $this_email,

 );

 $make_user = entity_create('user', $new_user);

 user_save($make_user);

 $found_user = user_load_by_name($this_email);

 }

   $user = $found_user;

 //  user_login_finalize();

 backdrop_goto( 'login-report' );

  

Fingers crossed,

   Tom G.

Comments

Thanks for the lead, I will dig in....

I'm pretty sure but not 100% certain: You are probably running into issues because Dashboard is enabled, which sets the $_GET['destination'] supervariable. backdrop_goto() will not work properly once that variable is set. You have a few options:

  • Disable Dashboard (but you may find other implementations of hook_user_login() that set it)
  • Unset $_GET['destination'] manually after calling  user_login_finalize() and before backdrop_goto()
  • Implement your own hook_user_login() that does the above. 

Ahh, awesome!

I will have to explore which option will be best, but for now I tried the unset($_GET['destination']) and the goto works as you predicted.

Many Thanks!