1

I want to change the default login functionality to look at a web service and if true log in else do not log in.

I have tried to use in hook_form_alter

 $form['#submit'] = 'user_change_login_submit'; 
  $form['actions']['submit']['#submit'][]= 'user_change_login_submit';

But it doesn't call this function.

1

I had a similar functionality in a project a while ago and I solved it by adding a validation handler and doing the check in that.

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  // Replace the drupal authenticate function is it's used as validation.
  if (isset($form['#validate']) && is_array($form['#validate']) && ($key = array_search('user_login_authenticate_validate', $form['#validate']))) {
    $form['#validate'][$key] = 'mymodule_login_authenticate_validate';
  }
}

function mymodule_login_authenticate_validate($form, &$form_state) {
  // Set 
  $account = mymodule_authenticate($form_state);
  if ($account) {
    $form_state['uid'] = $account->uid;
  }
}


function mymodule_authenticate($form_state) {
  // Your magic code here
  // In my project I either created a new user or updated an existing user and set $account as that.

  // And if everything went well in your code, finalize login and return account
  user_login_finalize($form_state['values']);
  return $account;
}

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.