--- cas.module Tue Nov 10 10:18:36 2009 +++ cas.module Fri Jan 22 11:59:48 2010 @@ -11,6 +11,9 @@ define('CAS_NO_VERIFY', 'none'); define('CAS_VERIFY', 'verify'); define('CAS_CA_VERIFY', 'ca_verify'); +define('CAS_NO_LINK',0); +define('CAS_ADD_LINK',1); +define('CAS_MAKE_DEFAULT',2); /** * Invokes hook_auth_transform() in every module. @@ -698,6 +701,30 @@ '#default_value' => variable_get('cas_useldap_groups', 0), '#description' => t('Activate this option if you want to extract the user groups from an LDAP directory. Ldapgroups module must be enabled and configured.'), ); + + $form['login'] = array( + '#type' => 'fieldset', + '#title' => t('Login form settings'), + '#collapsible' => true, + '#collapsed' => true, + ); + + $form['login']['cas_login_form'] = array( + '#type' => 'radios', + '#title' => t('Add CAS link to login forms'), + '#default_value' => variable_get('cas_login_form', CAS_NO_LINK), + '#options' => array(CAS_NO_LINK => 'Do not add link to login forms', CAS_ADD_LINK => 'Add link to login forms', + CAS_MAKE_DEFAULT => 'Make CAS login default on login forms'), + ); + + $form['login']['cas_login_id'] = array( + '#type' => 'textfield', + '#title' => t('CAS username identifier'), + '#default_value' => variable_get('cas_login_id', 'CAS username'), + '#size' => 30, + '#maxlength' => 55, + '#description' => t('What you call your CAS credentials.'), + ); return system_settings_form($form); } @@ -898,6 +925,47 @@ function cas_form_alter(&$form, $form_state, $form_id) { //drupal_set_message($form_id.'
'.print_r($form,1).'
'); switch ($form_id) { + case 'user_login': + case 'user_login_block': + if (variable_get('cas_login_form', CAS_NO_LINK) == CAS_NO_LINK) { + break; + } + drupal_add_css(drupal_get_path('module', 'cas') .'/cas.css', 'module'); + drupal_add_js(drupal_get_path('module', 'cas') .'/cas.js'); + if ($form_state['post']['cas_identifier'] == 1) { + $form['name']['#required'] = FALSE; + $form['pass']['#required'] = FALSE; + unset($form['#submit']); + $form['#validate'] = array('cas_login_validate'); + } + + $items = array(); + $items[] = array( + 'data' => l(t('Log in using your @cas_login_id', array('@cas_login_id' => variable_get('cas_login_id', 'CAS username'))), '', array('fragment' => ' ', 'external' => TRUE)), + 'class' => 'cas-link', + ); + $items[] = array( + 'data' => l(t('Users without a @cas_login_id click here', array('@cas_login_id' => variable_get('cas_login_id', 'CAS username'))), '', array('fragment' => ' ', 'external' => TRUE)), + 'class' => 'uncas-link', + ); + + $form['cas_links'] = array( + '#value' => theme('item_list', $items), + '#weight' => 1, + ); + + $form['links']['#weight'] = 2; + + $form['cas_identifier'] = array( + '#type' => 'checkbox', + '#title' => t('Log in using NetID'), + '#default_value' => (variable_get('cas_login_form', CAS_NO_LINK) == CAS_ADD_LINK ? 0 : 1), + '#weight' => -1, + '#description' => t("When you click 'Log in' you will be redirected to a page where you can securely enter your %cas_login_id and password", array('%cas_login_id' => variable_get('cas_login_id', 'CAS username'))), + ); + $form['cas.return_to'] = array('#type' => 'hidden', '#value' => 'cas'); + break; + case 'user_profile_form': //make the email field hidden and force the value to the default. if (variable_get('cas_hide_email', 0)) { @@ -949,6 +1017,18 @@ break; } } + +/** + * Login form _validate hook + */ +function cas_login_validate($form, &$form_state) { + if($form_state['values']['persistent_login'] == 1) { + $_SESSION['cas_remember'] = 1; + } + $_REQUEST['destination'] = 'cas'; + drupal_redirect_form($form, 'cas'); +} + /* ** LDAPAuth interfacing - BEGIN */