function openid_form_alter in Drupal 6
Implementation of hook_form_alter : adds OpenID login to the login forms.
File
- modules/
openid/ openid.module, line 77 - Implement OpenID Relying Party support for Drupal
Code
function openid_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'user_login_block' || $form_id == 'user_login') {
drupal_add_css(drupal_get_path('module', 'openid') . '/openid.css', 'module');
drupal_add_js(drupal_get_path('module', 'openid') . '/openid.js');
if (!empty($form_state['post']['openid_identifier'])) {
$form['name']['#required'] = FALSE;
$form['pass']['#required'] = FALSE;
unset($form['#submit']);
$form['#validate'] = array(
'openid_login_validate',
);
}
$items = array();
$items[] = array(
'data' => l(t('Log in using OpenID'), '#'),
'class' => 'openid-link',
);
$items[] = array(
'data' => l(t('Cancel OpenID login'), '#'),
'class' => 'user-link',
);
$form['openid_links'] = array(
'#value' => theme('item_list', $items),
'#weight' => 1,
);
$form['links']['#weight'] = 2;
$form['openid_identifier'] = array(
'#type' => 'textfield',
'#title' => t('Log in using OpenID'),
'#size' => $form_id == 'user_login' ? 58 : 13,
'#maxlength' => 255,
'#weight' => -1,
'#description' => l(t('What is OpenID?'), 'http://openid.net/', array(
'external' => TRUE,
)),
);
$form['openid.return_to'] = array(
'#type' => 'hidden',
'#value' => url('openid/authenticate', array(
'absolute' => TRUE,
'query' => user_login_destination(),
)),
);
}
elseif ($form_id == 'user_register' && 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 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['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;
}