From d16574f0702d7bafa35b27ed8961580ad0a671ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Thu, 24 Jan 2013 13:07:59 +0100 Subject: [PATCH] new branch which introduces display names first commit with some infrastructure code --- lib/public/user.php | 10 +++++++++- lib/user.php | 41 ++++++++++++++++++++++++++++++++++++++++- lib/user/backend.php | 11 +++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/lib/public/user.php b/lib/public/user.php index 204d8e4c0f..2d22bdd96c 100644 --- a/lib/public/user.php +++ b/lib/public/user.php @@ -51,7 +51,15 @@ class User { public static function getUsers($search = '', $limit = null, $offset = null) { return \OC_USER::getUsers(); } - + + /** + * @brief get the user display name of the user currently logged in. + * @return string display name + */ + public static function getDisplayName() { + return \OC_USER::getDisplayName(); + } + /** * @brief Check if the user is logged in * @returns true/false diff --git a/lib/user.php b/lib/user.php index fd0ed6ecd3..d6d47293cb 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; } @@ -264,6 +265,31 @@ class OC_User { public static function setUserId($uid) { $_SESSION['user_id'] = $uid; } + + /** + * @brief Sets user display name for session + */ + private static function setDisplayName($uid) { + $_SESSION['display_name'] = self::determineDisplayName($uid); + } + + /** + * @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 @@ -319,7 +345,20 @@ class OC_User { return false; } } - + + /** + * @brief get the display name of the user currently logged in. + * @return string uid or false + */ + public static function getDisplayName() { + if( isset($_SESSION['user_id']) AND $_SESSION['user_id'] ) { + return $_SESSION['display_name']; + } + else{ + return false; + } + } + /** * @brief Autogenerate a password * @returns string diff --git a/lib/user/backend.php b/lib/user/backend.php index 2a95db9369..47c92f5fe7 100644 --- a/lib/user/backend.php +++ b/lib/user/backend.php @@ -35,6 +35,7 @@ define('OC_USER_BACKEND_CREATE_USER', 0x000001); define('OC_USER_BACKEND_SET_PASSWORD', 0x000010); define('OC_USER_BACKEND_CHECK_PASSWORD', 0x000100); define('OC_USER_BACKEND_GET_HOME', 0x001000); +define('OC_USER_BACKEND_GET_DISPLAYNAME', 0x010000); /** @@ -50,6 +51,7 @@ abstract class OC_User_Backend implements OC_User_Interface { OC_USER_BACKEND_SET_PASSWORD => 'setPassword', OC_USER_BACKEND_CHECK_PASSWORD => 'checkPassword', OC_USER_BACKEND_GET_HOME => 'getHome', + OC_USER_BACKEND_GET_DISPLAYNAME => 'getDisplayName', ); /** @@ -120,4 +122,13 @@ abstract class OC_User_Backend implements OC_User_Interface { public function getHome($uid) { return false; } + + /** + * @brief get display name of the user + * @param $uid user ID of the user + * @return display name + */ + public function getDisplayName($uid) { + return $uid; + } }