Index: modules/openid/openid.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/openid/openid.module,v
retrieving revision 1.68
diff -u -9 -p -r1.68 openid.module
--- modules/openid/openid.module	4 Dec 2009 16:49:47 -0000	1.68
+++ modules/openid/openid.module	15 Dec 2009 18:17:33 -0000
@@ -59,24 +59,27 @@ function openid_help($path, $arg) {
       $output .= '</dl>';
       return $output;
   }
 }
 
 /**
  * Implements hook_user_insert().
  */
 function openid_user_insert(&$edit, $account, $category) {
-  if (isset($_SESSION['openid']['values'])) {
+  if (isset($_SESSION['openid']['response'])) {
     // The user has registered after trying to login via OpenID.
     if (variable_get('user_email_verification', TRUE)) {
       drupal_set_message(t('Once you have verified your e-mail address, you may log in via OpenID.'));
     }
-    user_set_authmaps($account, array('authname_openid' => $_SESSION['openid']['values']['response']['openid.claimed_id']));
+    else {
+      module_invoke_all('openid_response', $_SESSION['openid']['response'], $account);
+    }
+    user_set_authmaps($account, array('authname_openid' => $_SESSION['openid']['response']['openid.claimed_id']));
     unset($_SESSION['openid']);
   }
 }
 
 /**
  * Implements hook_form_FORM_ID_alter().
  */
 function openid_form_user_login_block_alter(&$form, &$form_state) {
   _openid_user_login_form_alter($form, $form_state);
@@ -127,35 +130,40 @@ function _openid_user_login_form_alter(&
   $form['openid.return_to'] = array('#type' => 'hidden', '#value' => url('openid/authenticate', array('absolute' => TRUE, 'query' => user_login_destination())));
 }
 
 /**
  * Implements hook_form_alter().
  *
  * Adds OpenID login to the login forms.
  */
 function openid_form_user_register_form_alter(&$form, &$form_state) {
-  if (isset($_SESSION['openid']['values'])) {
+  if (isset($_SESSION['openid']['response'])) {
     // We were unable to auto-register a new user. Prefill the registration
     // form with the values we have.
-    $form['account']['name']['#default_value'] = $_SESSION['openid']['values']['name'];
-    $form['account']['mail']['#default_value'] = $_SESSION['openid']['values']['mail'];
+    $response = $_SESSION['openid']['response'];
+    if (!empty($response['openid.sreg.nickname'])) {
+      $form['account']['name']['#default_value'] = $response['openid.sreg.nickname'];
+    }
+    if (!empty($response['openid.sreg.email'])) {
+      $form['account']['mail']['#default_value'] = $response['openid.sreg.email'];
+    }
 
     // If user_email_verification is off, hide the password field and just fill
     // with random password to avoid confusion.
     if (!variable_get('user_email_verification', TRUE)) {
       $form['pass']['#type'] = 'hidden';
       $form['pass']['#value'] = user_password();
     }
-    $form['openid_display'] = array(
+    $form['account']['openid_display'] = array(
       '#type' => 'item',
       '#title' => t('Your OpenID'),
       '#description' => t('This OpenID will be attached to your account after registration.'),
-      '#markup' => check_plain($_SESSION['openid']['values']['response']['openid.claimed_id']),
+      '#markup' => check_plain($response['openid.claimed_id']),
     );
   }
 }
 
 /**
  * Login form _validate hook
  */
 function openid_login_validate($form, &$form_state) {
   $return_to = $form_state['values']['openid.return_to'];
@@ -432,70 +440,25 @@ function openid_authentication($response
         // Let other modules act on OpenID login
         module_invoke_all('openid_response', $response, $account);
       }
     }
     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)) {
+     drupal_set_message(t('Complete the form below to create an account. You will be able to log into this account using your OpenID. 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'))));
     // Register new user
-    $form_state['build_info']['args'] = array();
-    $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;
-
-    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', $form_state);
-      drupal_prepare_form('user_register_form', $form, $form_state);
-      drupal_validate_form('user_register_form', $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($_GET['destination']);
-      drupal_goto('user/register', array('query' => $destination));
-    }
-    else {
-      unset($form_state['values']['response']);
-      $account = user_save(drupal_anonymous_user(), $form_state['values']);
-      // Terminate if an error occurred during user_save().
-      if (!$account) {
-        drupal_set_message(t("Error saving user account."), 'error');
-        drupal_goto();
-      }
-      user_set_authmaps($account, array("authname_openid" => $identity));
-      // Load global $user and perform final login tasks.
-      $form_state['uid'] = $account->uid;
-      user_login_submit(array(), $form_state);
-      // Let other modules act on OpenID login
-      module_invoke_all('openid_response', $response, $account);
-    }
-    drupal_redirect_form($form_state);
+    $_SESSION['openid']['response'] = $response;
+    // We'll want to redirect back to the same place.
+    $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');
   }
   drupal_goto();
 }
 
 function openid_association_request($public) {
   module_load_include('inc', 'openid');
Index: modules/openid/openid.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/openid/openid.test,v
retrieving revision 1.8
diff -u -9 -p -r1.8 openid.test
--- modules/openid/openid.test	24 Nov 2009 05:20:48 -0000	1.8
+++ modules/openid/openid.test	15 Dec 2009 18:17:33 -0000
@@ -160,18 +160,22 @@ class OpenIDFunctionalTest extends Drupa
     // Fill out and submit the login form.
     $edit = array('openid_identifier' => $identity);
     $this->drupalPost(NULL, $edit, t('Log in'));
 
     // Check we are on the OpenID redirect form.
     $this->assertTitle(t('OpenID redirect'), t('OpenID redirect page was displayed.'));
         
     // Submit form to the OpenID Provider Endpoint.
     $this->drupalPost(NULL, array(), t('Send'));
+    $this->assertRaw(t('Complete the form below to create an account. You will be able to log into this account using your OpenID. 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'))), t('User was asked to complete the registration process.'));
+
+    // Submit the form using the default values based on SREG.
+    $this->drupalPost(NULL, array(), t('Create new account'));
     $this->assertText('john', t('User was logged in.'));
 
     $user = user_load_by_name('john');
     $this->assertTrue($user, t('User was registered with right username.'));
     $this->assertEqual($user->mail, 'john@example.com', t('User was registered with right email address.'));
   }
 
   /**
    * Test OpenID auto-registration with a provider that supplies invalid SREG
@@ -190,20 +194,22 @@ class OpenIDFunctionalTest extends Drupa
     // Fill out and submit the login form.
     $edit = array('openid_identifier' => $identity);
     $this->drupalPost(NULL, $edit, t('Log in'));
 
     // Check we are on the OpenID redirect form.
     $this->assertTitle(t('OpenID redirect'), t('OpenID redirect page was displayed.'));
         
     // Submit form to the OpenID Provider Endpoint.
     $this->drupalPost(NULL, array(), t('Send'));
+    $this->assertRaw(t('Complete the form below to create an account. You will be able to log into this account using your OpenID. 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'))), t('User was asked to complete the registration process.'));
 
-    $this->assertRaw(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'))), t('User was asked to complete the registration process manually.'));
+    // Submit the form using the default values based on SREG.
+    $this->drupalPost(NULL, array(), t('Create new account'));
     $this->assertRaw(t('The name %name is already taken.', array('%name' => $this->web_user->name)), t('Form validation error for username was displayed.'));
     $this->assertRaw(t('The e-mail address %mail is not valid.', array('%mail' => 'mail@invalid#')), t('Form validation error for e-mail address was displayed.'));
 
     // Enter username and e-mail address manually.
     $edit = array('name' => 'john', 'mail' => 'john@example.com');
     $this->drupalPost(NULL, $edit, t('Create new account'));
     $this->assertRaw(t('Once you have verified your e-mail address, you may log in via OpenID.'), t('User was asked to verify e-mail address.'));
 
     $user = user_load_by_name('john');
@@ -234,20 +240,22 @@ class OpenIDFunctionalTest extends Drupa
     // Fill out and submit the login form.
     $edit = array('openid_identifier' => $identity);
     $this->drupalPost(NULL, $edit, t('Log in'));
 
     // Check we are on the OpenID redirect form.
     $this->assertTitle(t('OpenID redirect'), t('OpenID redirect page was displayed.'));
         
     // Submit form to the OpenID Provider Endpoint.
     $this->drupalPost(NULL, array(), t('Send'));
+    $this->assertRaw(t('Complete the form below to create an account. You will be able to log into this account using your OpenID. 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'))), t('User was asked to complete the registration process.'));
 
-    $this->assertRaw(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'))), t('User was asked to complete the registration process manually.'));
+    // Submit the form using the default values based on SREG.
+    $this->drupalPost(NULL, array(), t('Create new account'));
     $this->assertNoRaw(t('You must enter a username.'), t('Form validation error for username was not displayed.'));
     $this->assertNoRaw(t('You must enter an e-mail address.'), t('Form validation error for e-mail address was not displayed.'));
 
     // Enter username and e-mail address manually.
     $edit = array('name' => 'john', 'mail' => 'john@example.com');
     $this->drupalPost(NULL, $edit, t('Create new account'));
     $this->assertRaw(t('Once you have verified your e-mail address, you may log in via OpenID.'), t('User was asked to verify e-mail address.'));
 
     $user = user_load_by_name('john');
