You are here

function cas_user_operations_create_username in CAS 6.3

Same name and namespace in other branches
  1. 7 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 445
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) {
  foreach ($uids as $uid) {
    $account = user_load(array(
      'uid' => (int) $uid,
    ));
    $count = db_result(db_query("SELECT COUNT(*) FROM {cas_user} c WHERE c.uid <> %d AND c.cas_name = '%s'", $account->uid, $account->name));
    if ($count) {
      drupal_set_message(t('CAS username %username already in use.', array(
        '%username' => $account->name,
      )), 'error');
      continue;
    }
    @db_query("INSERT INTO {cas_user} (uid, cas_name) VALUES (%d, '%s')", $account->uid, $account->name);
  }
}