You are here

function cas_batch_user_add in CAS 7

CAS user creation batch callback.

Parameters

$cas_name: The name of the CAS user.

1 string reference to 'cas_batch_user_add'
cas_add_user_form_submit in ./cas.user.inc

File

./cas.batch.inc, line 14
Provides CAS batch functions.

Code

function cas_batch_user_add($cas_name, &$context) {
  $options = array(
    'invoke_cas_user_presave' => TRUE,
  );

  // Remove any whitespace around usernames.
  $cas_name = trim($cas_name);

  // Check if the account already exists.
  $existing_account = cas_user_load_by_name($cas_name);
  if ($existing_account == TRUE) {
    $uri = entity_uri('user', $existing_account);
    $context['results']['messages']['already_exist'][] = t('<a href="@url">%name</a>', array(
      '@url' => url($uri['path'], $uri['options']),
      '%name' => format_username($existing_account),
    ));
    return;
  }
  $account = cas_user_register($cas_name, $options);

  // Display error if user creation fails.
  if (!$account) {
    $context['results']['messages']['error'][] = t("@cas_name", array(
      '@cas_name' => $cas_name,
    ));
  }
  else {
    $uri = entity_uri('user', $account);
    $context['results']['messages']['newly_created'][] = t('<a href="@url">%name</a>', array(
      '@url' => url($uri['path'], $uri['options']),
      '%name' => format_username($account),
    ));
    return $account;
  }
}