diff options
author | Björn Schießle <schiessle@owncloud.com> | 2013-01-24 13:07:59 +0100 |
---|---|---|
committer | Björn Schießle <schiessle@owncloud.com> | 2013-01-24 13:07:59 +0100 |
commit | d16574f0702d7bafa35b27ed8961580ad0a671ae (patch) | |
tree | c859da65474e37a7c2c537096dbebc2d86ba9b63 /lib | |
parent | f9a9fc5670505c4b3af9ca7b1294730e00330a3b (diff) | |
download | nextcloud-server-d16574f0702d7bafa35b27ed8961580ad0a671ae.tar.gz nextcloud-server-d16574f0702d7bafa35b27ed8961580ad0a671ae.zip |
new branch which introduces display names
first commit with some infrastructure code
Diffstat (limited to 'lib')
-rw-r--r-- | lib/public/user.php | 10 | ||||
-rw-r--r-- | lib/user.php | 41 | ||||
-rw-r--r-- | 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 204d8e4c0f1..2d22bdd96c8 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 fd0ed6ecd3a..d6d47293cbb 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 2a95db93690..47c92f5fe7b 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; + } } |