openid_authentication

  1. drupal
    1. drupal6
    2. drupal7
Versionen
drupal6 – drupal7 openid_authentication($response)

Authenticate a user or attempt registration.

Übergabeparameter

$response Response values from the OpenID Provider.

Code

modules/openid/openid.module, line 412

<?php
function openid_authentication($response) {
  module_load_include('inc', 'openid');

  $identity = $response['openid.claimed_id'];

  $account = user_external_load($identity);
  if (isset($account->uid)) {
    if (!variable_get('user_email_verification', TRUE) || $account->login) {
      user_external_login($account, $_SESSION['openid']['user_login_values']);
    }
    else {
      drupal_set_message(t('You must validate your email address for this account before logging in via OpenID'));
    }
  }
  elseif (variable_get('user_register', 1)) {
    // Register new user
    $form_state['redirect'] = NULL;
    $form_state['values']['name'] = (empty($response['openid.sreg.nickname'])) ? '' : $response['openid.sreg.nickname'];
    $form_state['values']['mail'] = (empty($response['openid.sreg.email'])) ? '' : $response['openid.sreg.email'];
    $form_state['values']['pass']  = user_password();
    $form_state['values']['status'] = variable_get('user_register', 1) == 1;
    $form_state['values']['response'] = $response;
    $form_state['values']['auth_openid'] = $identity;

    if (empty($response['openid.sreg.email']) && empty($response['openid.sreg.nickname'])) {
      drupal_set_message(t('Please 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');
      $success = FALSE;
    }
    else {
      $form = drupal_retrieve_form('user_register', $form_state);
      drupal_prepare_form('user_register', $form, $form_state);
      drupal_validate_form('user_register', $form, $form_state);
      $success = !form_get_errors();
      if (!$success) {
        drupal_set_message(t('Account registration using the information provided by your OpenID provider failed due to the reasons listed below. Please 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.
        $messages = drupal_get_messages('error');
        foreach ($messages['error'] as $message) {
          drupal_set_message( $message, 'error');
        }
      }
    }
    if (!$success) {
      // We were unable to register a valid new user, redirect to standard
      // user/register and prefill with the values we received.
      $_SESSION['openid']['values'] = $form_state['values'];
      // We'll want to redirect back to the same place.
      $destination = drupal_get_destination();
      unset($_REQUEST['destination']);
      drupal_goto('user/register', $destination);
    }
    else {
      unset($form_state['values']['response']);
      $account = user_save('', $form_state['values']);
      // Terminate if an error occured during user_save().
      if (!$account) {
        drupal_set_message(t("Error saving user account."), 'error');
        drupal_goto();
      }
      user_external_login($account);
    }
    drupal_redirect_form($form, $form_state['redirect']);
  }
  else {
    drupal_set_message(t('Only site administrators can create new user accounts.'), 'error');
  }
  drupal_goto();
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen