function openid_authentication

Authenticate a user or attempt registration.

Parameters

$response Response values from the OpenID Provider.:

1 call to openid_authentication()
openid_authentication_page in drupal/core/modules/openid/openid.pages.inc
Menu callback; Process an OpenID authentication.

File

drupal/core/modules/openid/openid.module, line 720
Implement OpenID Relying Party support for Drupal

Code

function openid_authentication($response) {
  $identity = $response['openid.claimed_id'];
  $account = user_external_load($identity);
  if (isset($account->uid)) {
    if (!config('user.settings')
      ->get('verify_mail') || $account->login) {

      // Check if user is blocked.
      $state['values']['name'] = $account->name;
      user_login_name_validate(array(), $state);
      if (!form_get_errors()) {

        // Load global $user and perform final login tasks.
        $form_state['uid'] = $account->uid;
        user_login_form_submit(array(), $form_state);
      }
    }
    else {
      drupal_set_message(t('You must validate your email address for this account before logging in via OpenID.'));
    }

    // Let other modules act on OpenID login
    module_invoke_all('openid_response', $response, $account);
  }
  elseif (config('user.settings')
    ->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY) {

    // Register new user.
    // Save response for use in openid_form_user_register_form_alter().
    $_SESSION['openid']['response'] = $response;
    $form_state['values'] = array();
    $form_state['values']['op'] = t('Create new account');
    $account = entity_create('user', array());
    entity_form_submit($account, 'register', $form_state);
    if (empty($form_state['user'])) {
      module_invoke_all('openid_response', $response, NULL);
    }
    else {
      module_invoke_all('openid_response', $response, $form_state['user']);
      drupal_goto();
    }
    $messages = drupal_get_messages('error');
    if (empty($form_state['values']['name']) || empty($form_state['values']['mail'])) {

      // If the OpenID provider did not provide both a user name and an email
      // address, ask the user to complete the registration manually instead of
      // showing the error messages about the missing values generated by FAPI.
      drupal_set_message(t('Complete the registration by filling out the form below. If you already have an account, you can <a href="@login">log in</a> now and add your OpenID under "My account".', array(
        '@login' => url('user/login'),
      )), 'warning');
    }
    else {
      drupal_set_message(t('Account registration using the information provided by your OpenID provider failed due to the reasons listed below. Complete the registration by filling out the form below. If you already have an account, you can <a href="@login">log in</a> now and add your OpenID under "My account".', array(
        '@login' => url('user/login'),
      )), 'warning');

      // Append form validation errors below the above warning.
      foreach ($messages['error'] as $message) {
        drupal_set_message($message, 'error');
      }
    }

    // We were unable to register a valid new user. Redirect to the normal
    // registration page and prefill with the values we received.
    $destination = drupal_get_destination();
    unset($_GET['destination']);
    drupal_goto('user/register', array(
      'query' => $destination,
    ));
  }
  else {
    drupal_set_message(t('Only site administrators can create new user accounts.'), 'error');
    module_invoke_all('openid_response', $response, NULL);
  }
  drupal_goto();
}