You are here

function _cas_name_element_validate in CAS 7

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

Form element 'cas_name' validator.

If the element is displaying an existing {cas_user} entry, set #cas_user_aid to the corresponding 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
Implements hook_form_alter().
cas_user_add in ./cas.pages.inc
Form builder; Add a CAS identity.

File

./cas.module, line 1074
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;
  }
  $query = db_select('cas_user')
    ->fields('cas_user', array(
    'uid',
  ))
    ->condition('cas_name', $element['#value']);

  // 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'])) {
    $query
      ->condition('aid', $element['#cas_user_aid'], '<>');
  }
  $uid = $query
    ->execute()
    ->fetchField();
  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'),
    )));
  }
}