You are here

function cas_user_operations_create_username in CAS 7

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

Callback function to assign a CAS username to the account.

Parameters

$uids: An array of user ids. For each account, a CAS username is created with the same name as the Drupal username.

See also

cas_user_operations()

1 string reference to 'cas_user_operations_create_username'
cas_user_operations in ./cas.module
Implements hook_user_operations().

File

./cas.module, line 500
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_user_operations_create_username($uids) {
  $accounts = user_load_multiple($uids);
  foreach ($accounts as $account) {
    $count = db_select('cas_user', 'c')
      ->condition('cas_name', $account->name)
      ->condition('uid', $account->uid, '<>')
      ->countQuery()
      ->execute()
      ->fetchfield();
    if ($count) {
      drupal_set_message(t('CAS username %username already in use.', array(
        '%username' => $account->name,
      )), 'error');
      continue;
    }
    db_merge('cas_user')
      ->key(array(
      'cas_name' => $account->name,
    ))
      ->fields(array(
      'uid' => $account->uid,
    ))
      ->execute();
  }
}