function ldap_servers_token_tokenize_user_account in Lightweight Directory Access Protocol (LDAP) 8.2
Same name and namespace in other branches
- 7.2 ldap_servers/ldap_servers.tokens.inc \ldap_servers_token_tokenize_user_account()
Parameters
drupal user object $user_account:
array or 'all' $token_keys 'all' signifies return: all token/value pairs available; otherwise array lists token keys (e.g. property.name ...NOT [property.name])
string $pre prefix of token:
string $post suffix of token:
Return value
should return token/value pairs in array such as 'status' => 1 'uid' => 17
1 call to ldap_servers_token_tokenize_user_account()
- ldap_servers_token_replace in ldap_servers/
ldap_servers.tokens.inc
File
- ldap_servers/
ldap_servers.tokens.inc, line 348 - collection of functions related to ldap tokens
Code
function ldap_servers_token_tokenize_user_account($user_account, $token_keys = 'all', $pre = LDAP_SERVERS_TOKEN_PRE, $post = LDAP_SERVERS_TOKEN_POST) {
$detailed_watchdog_log = config('ldap_help.settings')
->get('watchdog_detail');
$tokens = array();
$user_entered_password_available = (bool) ldap_user_ldap_provision_pwd('get');
// ldapUserPwd((property_exists($user_account, 'ldapUserPwd') && $user_account->ldapUserPwd));
if ($token_keys == 'all') {
// add lowercase keyed entries to ldap array
foreach ((array) $user_account as $property_name => $value) {
if (is_scalar($value) && $property_name != 'password') {
$token_keys[] = 'property.' . $property_name;
if (drupal_strtolower($property_name) != $property_name) {
$token_keys[] = 'property.' . drupal_strtolower($property_name);
}
}
elseif (isset($user_account->{$attr_name}['und'][0]['value']) && is_scalar($user_account->{$attr_name}['und'][0]['value'])) {
$token_keys[] = 'field.' . $property_name;
if (drupal_strtolower($property_name) != $property_name) {
$token_keys[] = 'field.' . drupal_strtolower($property_name);
}
}
else {
// field or property with no value, so no token can be generated
}
}
$ldap_user_conf_admin = new LdapUserConfAdmin();
if ($ldap_user_conf->setsLdapPassword) {
$token_keys[] = 'password.random';
$token_keys[] = 'password.user-random';
}
}
foreach ($token_keys as $token_key) {
$parts = explode('.', $token_key);
$attr_type = $parts[0];
$attr_name = $parts[1];
$attr_conversion = isset($parts[2]) ? $parts[1] : 'none';
$value = FALSE;
$skip = FALSE;
switch ($attr_type) {
case 'field':
$value = @is_scalar($user_account->{$attr_name}['und'][0]['value']) ? $user_account->{$attr_name}['und'][0]['value'] : '';
break;
case 'property':
$value = @is_scalar($user_account->{$attr_name}) ? $user_account->{$attr_name} : '';
break;
case 'password':
switch ($attr_name) {
case 'user':
$pwd = ldap_user_ldap_provision_pwd('get');
break;
case 'user-random':
$pwd = ldap_user_ldap_provision_pwd('get');
$value = $pwd ? $pwd : user_password();
break;
case 'random':
$value = user_password();
break;
}
if (empty($value)) {
$skip = TRUE;
}
break;
}
if (!$skip) {
switch ($attr_conversion) {
case 'none':
break;
case 'to-md5':
$value = md5($value);
break;
case 'to-lowercase':
$value = drupal_strtolower($value);
break;
}
$tokens[$pre . $token_key . $post] = check_plain($value);
if ($token_key != drupal_strtolower($token_key)) {
$tokens[$pre . drupal_strtolower($token_key) . $post] = check_plain($value);
}
}
}
return $tokens;
}