1

I need to redirect users function of his role using external authenticate.

In my form_alter() I have:

$form['#validate'] = array(
  'user_login_name_validate',
  'beneficiaire_authenticate',
  'user_login_final_validate'
);
$form['#submit'][] = 'beneficiaire_user_login_dispatch';

My function to authenticate:

function beneficiaire_authenticate($form, &$form_state){
  module_load_include('inc', 'beneficiaire', 'ws');

    if('admin' == $form_state['values']['name']){
        user_login_authenticate_validate($form, $form_state);
    }else{
    $authResponse = beneficiaire_ws_authenticate($form_state['values']['name'], $form_state['values']['pass']);
        if($authResponse)   {
            user_external_login_register($form_state['values']['name'], 'beneficiaire');
            $account = user_external_load($form_state['values']['name']);
            //var_dump($account);exit();
            $form_state['uid'] = $account->uid;
            $account->roles[4]= 'beneficiaire';
            user_save($account);
      $_SESSION['account'] = $authResponse;
        }
    }
}

And finally my dispatch function where the aim is to redirect users function of their account status / type:

function beneficiaire_user_login_dispatch($form, &$form_state){
  if($_SESSION['account']->temporaire){
    drupal_goto('update-password');
  }else{
    drupal_goto('order');
  }
}

My point is, each user is always redirected to /node. How can I redirect them function of account status ?

Thanks

  • Have you tried with $form_state['redirect'] = 'path/to' ? or drupal_redirect_form ? – Gianni Di Falco Jan 23 '15 at 9:00
1

I've found a solution:

function beneficiaire_user_login($form, &$form_state){
  if($_SESSION['account']->temporaire){
    $_GET['destination'] = 'update-password';
  }else{
    $_GET['destination'] = 'order';
  }
}
  • 1
    Nice, looks very good. You also can use drupal_get_query_parameters (It returns An array containing query parameters, which can be used for url().) – Gianni Di Falco Jan 23 '15 at 9:09
0

You should check a few things:

  1. Use $form_state['redirect'] instead of drupal_goto
  2. Check other submit functions attached in $form['#submit'] array. Probably one has redirect to /node
  3. Follow Drupal coding standards :)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.