You are here

function _cas_name_element_validate in CAS 6.3

Same name and namespace in other branches
  1. 7 cas.module \_cas_name_element_validate()

Form element 'cas_name' validator.

If the element is disaplying an existing {cas_user} entry, set #cas_user_aid to the corresponing authmap id to avoid spurious validation errors.

3 string references to '_cas_name_element_validate'
cas_add_user_form in ./cas.user.inc
Creates a CAS user registration page.
cas_form_alter in ./cas.module
Implementation of hook_form_alter().
cas_user_add in ./cas.pages.inc
Form builder; Add a CAS identity.

File

./cas.module, line 979
Enables users to authenticate via a Central Authentication Service (CAS) Cas will currently work if the auto registration is turned on and will create user accounts automatically.

Code

function _cas_name_element_validate($element, &$form_state) {
  if (empty($element['#value'])) {

    // Nothing to validate if the name is empty.
    return;
  }

  // If set, we ignore entries with a specified authmap id. This is used on
  // the user/%user/edit page to not throw validation errors when we do not
  // change the CAS username.
  if (isset($element['#cas_user_aid'])) {
    $uid = db_result(db_query("SELECT uid FROM {cas_user} WHERE cas_name = '%s' AND aid <> %d", $element['#value'], $element['#cas_user_aid']));
  }
  else {
    $uid = db_result(db_query("SELECT uid FROM {cas_user} WHERE cas_name = '%s'", $element['#value']));
  }
  if ($uid !== FALSE) {

    // Another user is using this CAS username.
    form_set_error('cas_name', t('The CAS username is <a href="@edit-user-url">already in use</a> on this site.', array(
      '@edit-user-url' => url('user/' . $uid . '/edit'),
    )));
  }
}