From 0a5743b0ff62e105ec7852ef70b5e5ed3ce69176 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sun, 20 Feb 2011 13:28:32 +0000 Subject: [PATCH] easier switching to long user name suggestion --- lam/lib/modules/posixAccount.inc | 35 ++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/lam/lib/modules/posixAccount.inc b/lam/lib/modules/posixAccount.inc index 4d212c1d..ccd03814 100644 --- a/lam/lib/modules/posixAccount.inc +++ b/lam/lib/modules/posixAccount.inc @@ -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; + } + } ?>