diff options
Diffstat (limited to 'lib/user.php')
-rw-r--r-- | lib/user.php | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/user.php b/lib/user.php index 85240ce6b68..38259bceea5 100644 --- a/lib/user.php +++ b/lib/user.php @@ -251,6 +251,7 @@ class OC_User { if($uid && $enabled) { session_regenerate_id(true); self::setUserId($uid); + self::setDisplayName($uid); OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid, 'password'=>$password )); return true; } @@ -266,6 +267,48 @@ class OC_User { } /** + * @brief Sets user display name for session + */ + public static function setDisplayName($uid, $displayName = null) { + $result = false; + if ($displayName ) { + foreach(self::$_usedBackends as $backend) { + if($backend->implementsActions(OC_USER_BACKEND_SET_DISPLAYNAME)) { + if($backend->userExists($uid)) { + $success |= $backend->setDisplayName($uid, $displayName); + } + } + } + } else { + $displayName = self::determineDisplayName($uid); + $result = true; + } + if (OC_User::getUser() === $uid) { + $_SESSION['display_name'] = $displayName; + } + return $result; + } + + + /** + * @brief get display name + * @param $uid The username + * @returns string display name or uid if no display name is defined + * + */ + private static function determineDisplayName( $uid ) { + foreach(self::$_usedBackends as $backend) { + if($backend->implementsActions(OC_USER_BACKEND_GET_DISPLAYNAME)) { + $result=$backend->getDisplayName( $uid ); + if($result) { + return $result; + } + } + } + return $uid; + } + + /** * @brief Logs the current user out and kills all the session data * * Logout, destroys session @@ -321,6 +364,21 @@ class OC_User { } /** + * @brief get the display name of the user currently logged in. + * @return string uid or false + */ + public static function getDisplayName($user=null) { + if ( $user ) { + return self::determineDisplayName($user); + } else if( isset($_SESSION['display_name']) AND $_SESSION['display_name'] ) { + return $_SESSION['display_name']; + } + else{ + return false; + } + } + + /** * @brief Autogenerate a password * @returns string * @@ -420,6 +478,24 @@ class OC_User { } /** + * @brief Get a list of all users display name + * @returns associative array with all display names (value) and corresponding uids (key) + * + * Get a list of all display names and user ids. + */ + public static function getDisplayNames($search = '', $limit = null, $offset = null) { + $displayNames = array(); + foreach (self::$_usedBackends as $backend) { + $backendDisplayNames = $backend->getDisplayNames($search, $limit, $offset); + if (is_array($backendDisplayNames)) { + $displayNames = array_merge($displayNames, $backendDisplayNames); + } + } + ksort($displayNames); + return $displayNames; + } + + /** * @brief check if a user exists * @param string $uid the username * @param string $excludingBackend (default none) |