Index: cas.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/cas/cas.module,v retrieving revision 1.61 diff -u -r1.61 cas.module --- cas.module 10 Nov 2009 16:17:48 -0000 1.61 +++ cas.module 16 Feb 2010 17:12:31 -0000 @@ -1,5 +1,5 @@ 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_invite'] = array( + '#type' => 'textfield', + '#title' => t('CAS Login invitation'), + '#default_value' => variable_get('cas_login_invite', CAS_LOGIN_INVITE_DEFAULT), + '#size' => 55, + '#maxlength' => 80, + '#description' => t('Message users will see to invite them to log in with cas credentials .'), + ); + + $form['login']['cas_login_drupal_invite'] = array( + '#type' => 'textfield', + '#title' => t('Drupal login invitation'), + '#default_value' => variable_get('cas_login_drupal_invite',CAS_LOGIN_DRUPAL_INVITE_DEFAULT), + '#size' => 55, + '#maxlength' => 80, + '#description' => t('Message users will see to invite them to log in with drupal credentials.'), + ); + + $form['login']['cas_login_message'] = array( + '#type' => 'textfield', + '#title' => t('Redirection notification message'), + '#default_value' => variable_get('cas_login_message', CAS_LOGIN_REDIR_MESSAGE), + '#size' => 55, + '#maxlength' => 80, + '#description' => t('Message users see at the top of the cas login form to warn them that they are being redirected.'), + ); + return system_settings_form($form); } @@ -898,6 +946,48 @@ 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(variable_get('cas_login_invite',CAS_LOGIN_INVITE_DEFAULT)),'', array('fragment' => ' ', 'external' => TRUE)), + 'class' => 'cas-link', + ); + $items[] = array( + 'data' => l(t(variable_get('cas_login_drupal_invite',CAS_LOGIN_DRUPAL_INVITE_DEFAULT)),'', 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(variable_get('cas_login_redir_message',CAS_LOGIN_REDIR_MESSAGE)), + ); + $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)) { @@ -910,6 +1000,8 @@ } + + /* ** LDAPAuth interfacing - BEGIN */ @@ -949,6 +1041,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 */ @@ -957,7 +1061,7 @@ * LDAP Auxiliary functions */ function _get_ldap_config_name($user_name) { - module_load_include('module', 'ldap_integration', 'ldapauth'); + include_once('modules/ldap_integration/ldapauth.module'); $user_found = FALSE; $result = db_query("SELECT name FROM {ldapauth} WHERE status = '%d' ORDER BY sid", 1); while ($row = db_fetch_object($result)) {