function cas_roles_cas_user_alter in CAS roles 7
Same name and namespace in other branches
- 7.2 cas_roles.module \cas_roles_cas_user_alter()
Implements hook_cas_user_alter().
File
- ./
cas_roles.module, line 105 - Allows user account and profile attributes to be automatically populated using tokens. Provides basic tokens for attributes returned by the CAS server.
Code
function cas_roles_cas_user_alter(&$cas_user) {
$behavior = variable_get('cas_roles_behavior');
$require_a_role_create = variable_get('cas_roles_require_a_role_create', FALSE);
$require_a_role_login = variable_get('cas_roles_require_a_role_login', FALSE);
$relations = variable_get('cas_roles_relations', array(
'2' => NULL,
));
if ($behavior == CAS_ROLES_MATCH_REGEX) {
$role_candidates = cas_roles_candidates($cas_user);
$one_matches = FALSE;
// Check if one of the candidate roles matches a regular expression.
foreach (user_roles(TRUE) as $role) {
if (array_key_exists($role, $relations) && $relations[$role]) {
$matches = preg_grep($relations[$role], $role_candidates);
if (!empty($matches)) {
$one_matches = TRUE;
break;
}
}
}
if ($require_a_role_create && !$one_matches) {
$cas_user['register'] = FALSE;
// drupal_set_message(t('You can not log in on this site.'), 'error');
}
if ($require_a_role_login && !$one_matches) {
$cas_user['login'] = FALSE;
// drupal_set_message(t('You can not log in on this site.'), 'error');
}
}
}