easier switching to long user name suggestion

This commit is contained in:
Roland Gruber 2011-02-20 13:28:32 +00:00
parent ed42627653
commit 0a5743b0ff
1 changed files with 27 additions and 8 deletions

View File

@ -52,6 +52,8 @@ class posixAccount extends baseModule implements passwordService {
private $clearTextPassword;
/** caches the list of known UIDs */
private $cachedUIDList = null;
/** if set to true the suggested user name for John Doe will be john.doe instead of jdoe */
private $SUGGEST_LONG_USER_NAME = false;
/**
* This function fills the error message array with messages.
@ -897,14 +899,7 @@ class posixAccount extends baseModule implements passwordService {
if (!isset($this->attributes['uid'][0]) && ($this->getAccountContainer()->getAccountModule('inetOrgPerson') != null)) {
// fill default value for user ID with first/last name
$attrs = $this->getAccountContainer()->getAccountModule('inetOrgPerson')->getAttributes();
if (isset($attrs['sn'][0])) {
if (isset($attrs['givenName'][0]) && ($attrs['givenName'][0] != '')) {
$this->attributes['uid'][0] = preg_replace('/[^a-z0-9_-]/', '', strtolower($attrs['givenName'][0][0] . $attrs['sn'][0]));
}
else {
$this->attributes['uid'][0] = preg_replace('/[^a-z0-9_-]/', '', strtolower($attrs['sn'][0]));
}
}
$this->attributes['uid'][0] = $this->getUserNameSuggestion($attrs);
}
if (!isset($this->attributes['cn'][0]) || ($this->attributes['cn'][0] == '')) {
// set a default value for common name
@ -1844,6 +1839,30 @@ class posixAccount extends baseModule implements passwordService {
return $this->cachedUIDList;
}
/**
* Returns a suggestion for the user name.
* By deafult this wil be the first character of the first name plus the last name.
*
* @param array $attrs LDAP attributes
* @return String user name
*/
private function getUserNameSuggestion($attrs) {
if (isset($attrs['sn'][0])) {
if (isset($attrs['givenName'][0]) && ($attrs['givenName'][0] != '')) {
if ($this->SUGGEST_LONG_USER_NAME) {
return preg_replace('/[^a-z0-9_\\.-]/', '', strtolower($attrs['givenName'][0] . '.' . $attrs['sn'][0]));
}
else {
return preg_replace('/[^a-z0-9_-]/', '', strtolower($attrs['givenName'][0][0] . $attrs['sn'][0]));
}
}
else {
return preg_replace('/[^a-z0-9_-]/', '', strtolower($attrs['sn'][0]));
}
}
return null;
}
}
?>