0

We have a shared register function that multiple pieces of our app use. When registration is successful, we log the user in. But for some reason, when a user completes this project via browser in the web, they are not properly logged in.

$result = register_user($registration_data);
if($result['success'] == true) {
    // Log user in for web.
    $account = $result['user'];
    $uid = $account->uid;
    $account_id_array = array('uid' => $uid);
    user_login_submit(array(), $account_id_array);

We end up having to log the user in on form submit

function agfe_registration_step_three_submit($form, &$form_state) {
...
  $result = register_user($registration_data);
  if($result['success'] == true) {
    // Log user in for web.
    $account = $result['user'];
    $uid = $account->uid;
    $account_id_array = array('uid' => $uid);
    user_login_submit(array(), $account_id_array);
    $user = user_load($uid);
    user_login_finalize();
    drupal_goto('dashboard');

Why do we have to do this? shouldn't the first user_login_submit fully authenticate and set the user up to use the site?

  • I can see why the redirection doesn't work in the first version. It relies on the use of an actual form_state array which gets passed back to the form builder. Explicitly invoking form callbacks has a bad smell to it anyway, I'd rather repeat the code in my own function as you have almost done already. – Alfred Armstrong Dec 6 '19 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.