1

I am working on a custom module that will allow remote authentication via an API if a user attempting to log in is not an administrator. The module first does a hook_form_alter and in that function does a database query to see if the username logging in exists, in the users table, and if it does then a check is made in the user_roles table to see if the uid is an administrator. If the user is not an administrator then I do

array_unshift($form['#validate'], 'sgauth_user_form_validate');

Where sgauth is the module name

I then have the following function to use a new validation function

function sgauth_user_form_validate($form, &$form_state) {
  if (!sgauth_authenticate($form_state)) {
    form_set_error('name', t('Sorry, unrecognised username or password. <b>Have you forgotten your password?</b>'));
  }
  drupal_goto('<front>');
}

The validation function sgauth_authenticate($form_state) gets the username and password entered in the login form and make a call to an API and the user is known by the Authentication behind the API a token is returned. If the token is returned I do

user_external_login_register($username,'sgauth');

As I read the Drupal API documentation this should be all I need to enter this user into the users table and to make an entry in the authmap table. If the user_external_login_register succeeds then I return TRUE from the sgauth_authenticate($form_state) function which takes me back to the function sgauth_user_form_validate($form, &$form_state) and to

drupal_goto('<front>');

Which redirects to the site he page with the external user logged in.

All of the above works fine for me. It is probably not the best way of achieving what I need to do and I am always willing to be shown better methods or ideas.

My problem occurs when I enable Modal Forms for Login Links. The login for the local user (i.e. an administrator works fine) However for an external user I get an alert error box

An AJAX HTTP error occurred.

If I OK this error I still have the modal box visible so it appears the function creating the modal box has not completed. The actual login process has completed fine and if I navigate anywhere on the site the modal box disappears and I can work with the external user logged in.

I need to find what I am doing that is causing this error to be thrown and how to fix it. I have spent hours looking for answers in Google and also looking through the Drupal code for the Modal Form and can not see what might cause this issue.

I would appreciate some help in solving this issue.

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.