function cas_user_register in CAS 6.3
Same name and namespace in other branches
- 7 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_add_user_form_submit in ./
cas.user.inc - 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 - Implementation of hook_uninstall().
File
- ./
cas.module, line 1165 - 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 (db_result(db_query("SELECT COUNT(*) FROM {users} WHERE LOWER(name) = LOWER('%s')", $edit['name'])) > 0) {
return FALSE;
}
// Create the user account.
$account = user_save(drupal_anonymous_user(), $edit);
watchdog("user", 'new user: %n (CAS)', array(
'%n' => $account->name,
), WATCHDOG_NOTICE, l(t("edit user"), "admin/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);
}
return $account;
}