function cas_user_register in CAS 7
Same name and namespace in other branches
- 6.3 cas.module \cas_user_register()
Register a CAS user with some default values.
Parameters
$cas_name: The name of the CAS user.
$options: An associative array of options, with the following elements:
- 'edit': An array of fields and values for the new user. If omitted, reasonable defaults are used.
- 'invoke_cas_user_presave': Defaults to FALSE. Whether or not to invoke hook_cas_user_presave() on the newly created account.
Return value
The user object of the created user, or FALSE if the user cannot be created.
3 calls to cas_user_register()
- cas_batch_user_add in ./
cas.batch.inc - CAS user creation batch callback.
- cas_drush_user_create in ./
cas.drush.inc - Creates a new CAS user account.
- cas_login_check in ./
cas.module - Checks to see if the user needs to be logged in.
4 string references to 'cas_user_register'
- CasUserTestCase::testCasAutoRegister in ./
cas.test - Tests automatically registering a user on login.
- cas_admin_settings in ./
cas.admin.inc - Provides settings pages.
- cas_login_check in ./
cas.module - Checks to see if the user needs to be logged in.
- cas_uninstall in ./
cas.install - Implements hook_uninstall().
File
- ./
cas.module, line 1260 - 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_register($cas_name, $options = array()) {
// Add some reasonable defaults if they have not yet been provided.
$edit = isset($options['edit']) ? $options['edit'] : array();
$edit += array(
'name' => $cas_name,
'pass' => user_password(),
'init' => $cas_name,
'mail' => variable_get('cas_domain', '') ? $cas_name . '@' . variable_get('cas_domain', '') : '',
'status' => 1,
'roles' => array(),
);
$edit['roles'] += cas_roles();
$edit['cas_name'] = $cas_name;
// See if the user name is already taken.
if ((bool) db_select('users')
->fields('users', array(
'name',
))
->condition('name', db_like($edit['name']), 'LIKE')
->range(0, 1)
->execute()
->fetchField()) {
return FALSE;
}
// Create the user account.
$account = user_save(drupal_anonymous_user(), $edit);
watchdog("user", 'new user: %n (CAS)', array(
'%n' => format_username($account),
), WATCHDOG_NOTICE, l(t("edit user"), "user/edit/{$account->uid}"));
if (!empty($options['invoke_cas_user_presave'])) {
// Populate $edit with some basic properties.
$edit = array(
'cas_user' => array(
'name' => $cas_name,
),
);
// Allow other modules to make their own custom changes.
cas_user_module_invoke('presave', $edit, $account);
// Clean up extra variables before saving.
unset($edit['cas_user']);
$account = user_save($account, $edit);
}
// Reload to ensure that we have a fully populated user object.
return user_load($account->uid);
}