Index: modules/openid/openid.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/openid/openid.module,v
retrieving revision 1.50
diff -u -p -r1.50 openid.module
--- modules/openid/openid.module 10 Jun 2009 20:13:20 -0000 1.50
+++ modules/openid/openid.module 17 Jun 2009 08:26:57 -0000
@@ -128,15 +128,29 @@ function openid_form_user_register_alter
if (isset($_SESSION['openid']['values'])) {
// We were unable to auto-register a new user. Prefill the registration
// form with the values we have.
- $form['name']['#default_value'] = $_SESSION['openid']['values']['name'];
- $form['mail']['#default_value'] = $_SESSION['openid']['values']['mail'];
+ if (isset($_SESSION['openid']['values']['name']) && user_validate_name($_SESSION['openid']['values']['name'])) {
+ $form['name']['#default_value'] = $_SESSION['openid']['values']['name'];
+ }
+ if (isset($_SESSION['openid']['values']['mail']) && user_validate_mail($_SESSION['openid']['values']['mail'])) {
+ $form['mail']['#default_value'] = $_SESSION['openid']['values']['mail'];
+ }
+
// 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['auth_openid'] = array('#type' => 'hidden', '#value' => $_SESSION['openid']['values']['auth_openid']);
+ $form['auth_openid'] = array(
+ '#type' => 'hidden',
+ '#value' => isset($_SESSION['openid']['values']['auth_openid']) ? $_SESSION['openid']['values']['auth_openid'] : ''
+ );
+ $form['openid_display'] = array(
+ '#type' => 'item',
+ '#title' => t('Your OpenID'),
+ '#description' => t('This OpenID will be attached to your account after registration.'),
+ '#value' => isset($_SESSION['openid']['values']['auth_openid']) ? $_SESSION['openid']['values']['auth_openid'] : ''
+ );
}
}
@@ -419,8 +433,8 @@ function openid_authentication($response
// Register new user
$form_state['args'] = array();
$form_state['redirect'] = NULL;
- $form_state['values']['name'] = (empty($response['openid.sreg.nickname'])) ? $identity : $response['openid.sreg.nickname'];
- $form_state['values']['mail'] = (empty($response['openid.sreg.email'])) ? '' : $response['openid.sreg.email'];
+ $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;
@@ -430,7 +444,7 @@ function openid_authentication($response
if (form_get_errors()) {
// We were unable to register a valid new user, redirect to standard
// user/register and prefill with the values we received.
- drupal_set_message(t('OpenID registration failed for the reasons listed. You may register now, or if you already have an account you can log in now and add your OpenID under "My Account"', array('@login' => url('user/login'))), 'error');
+ drupal_set_message(t('OpenID registration failed for the reasons listed. Your OpenID persona did not provide the information requested, such as username and email or your OpenID provider does not support Simple Registration. Please complete the registration process manually, or log in now and add your OpenID under "My Account"', array('@login' => url('user/login'))), 'warning');
$_SESSION['openid']['values'] = $form_state['values'];
// We'll want to redirect back to the same place.
$destination = drupal_get_destination();
Index: modules/openid/openid.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/openid/openid.test,v
retrieving revision 1.2
diff -u -p -r1.2 openid.test
--- modules/openid/openid.test 6 May 2009 19:56:21 -0000 1.2
+++ modules/openid/openid.test 17 Jun 2009 08:26:58 -0000
@@ -156,6 +156,32 @@ class OpenIDFunctionalTest extends Drupa
$this->assertTrue($user, t('User was found.'));
$this->assertEqual($user->mail, 'johndoe@example.com', t('User was registered with right email address.'));
}
+
+ /**
+ * Test openID auto-registration with non SREG provider, e.g. when no
+ * nickname or email are provided.
+ */
+ function testRegisterUserNonSreg() {
+ variable_set('openid_non_sreg', TRUE);
+
+ // Load the front page to get the user login block.
+ $this->drupalGet('');
+
+ // Use a User-supplied Identity that is the URL of an XRDS document.
+ $identity = url('openid-test/yadis/xrds', array('absolute' => TRUE));
+
+ // Fill out and submit the login form.
+ $edit = array('openid_identifier' => $identity);
+ $this->drupalPost(NULL, $edit, t('Log in'));
+
+ // The OpenID module responds with an HTML form that is to be submitted
+ // to the OpenID Provider Endpoint. This is usually done automatically
+ // using JavaScript, but the SimpleTest browser does not support JavaScript,
+ // so the form is submitted manually instead.
+ $this->assertRaw('', t('JavaScript form submission found.'));
+ $this->drupalPost(NULL, array(), t('Send'));
+ $this->assertRaw(t('OpenID registration failed for the reasons listed. Your OpenID persona did not provide the information requested, such as username and email or your OpenID provider does not support Simple Registration. Please complete the registration process manually, or log in now and add your OpenID under "My Account"', array('@login' => url('user/login'))), t('User was asked to complete the registration process manually.'));
+ }
}
/**
Index: modules/openid/tests/openid_test.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/openid/tests/openid_test.module,v
retrieving revision 1.3
diff -u -p -r1.3 openid_test.module
--- modules/openid/tests/openid_test.module 10 Jun 2009 20:13:20 -0000 1.3
+++ modules/openid/tests/openid_test.module 17 Jun 2009 08:26:58 -0000
@@ -202,6 +202,17 @@ function _openid_test_endpoint_authentic
// Generate unique identifier for this authentication.
$nonce = _openid_nonce();
+ // Define the email and nickname to be used for the user registration, useful
+ // to simulate a non SREG provider.
+ if (variable_get('openid_non_sreg')) {
+ $nickname = 'http://scor.net/myopneid';
+ $email = '';
+ }
+ else {
+ $nickname = 'johndoe';
+ $email = 'johndoe@example.com';
+ }
+
// Generate response containing the user's identity. The openid.sreg.xxx
// entries contain profile data stored by the OpenID Provider (see OpenID
// Simple Registration Extension 1.0).
@@ -215,8 +226,8 @@ function _openid_test_endpoint_authentic
'openid.return_to' => $_REQUEST['openid_return_to'],
'openid.response_nonce' => $nonce,
'openid.assoc_handle' => 'openid-test',
- 'openid.sreg.email' => 'johndoe@example.com',
- 'openid.sreg.nickname' => 'johndoe',
+ 'openid.sreg.email' => $email,
+ 'openid.sreg.nickname' => $nickname,
'openid.signed' => 'op_endpoint,claimed_id,identity,return_to,response_nonce,assoc_handle',
);