Commit 9b24aaeb authored by Gábor Hojtsy's avatar Gábor Hojtsy

#216101 by Arancaytar, aufumy, incidentist, scor, c960657: Fix OpenID...

#216101 by Arancaytar, aufumy, incidentist, scor, c960657: Fix OpenID registration workfow in case of errors; let users prefill fields when username or email address was not provided or the values were not valid for Drupal.
parent 7f4acb7b
......@@ -125,6 +125,12 @@ function openid_form_alter(&$form, $form_state, $form_id) {
$form['pass']['#value'] = user_password();
}
$form['auth_openid'] = array('#type' => 'hidden', '#value' => $_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' => check_plain($_SESSION['openid']['values']['auth_openid']),
);
}
return $form;
}
......@@ -394,19 +400,34 @@ function openid_authentication($response) {
elseif (variable_get('user_register', 1)) {
// Register new user
$form_state['redirect'] = NULL;
$form_state['values']['name'] = (empty($response['openid.sreg.nickname'])) ? $identity : $response['openid.sreg.nickname'];
$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;
$form = drupal_retrieve_form('user_register', $form_state);
drupal_prepare_form('user_register', $form, $form_state);
drupal_validate_form('user_register', $form, $form_state);
if (form_get_errors()) {
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.
drupal_set_message(t('OpenID registration failed for the reasons listed. You may register now, or 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'))), 'error');
$_SESSION['openid']['values'] = $form_state['values'];
// We'll want to redirect back to the same place.
$destination = drupal_get_destination();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment