summaryrefslogtreecommitdiffstats
path: root/lib/user.php
diff options
context:
space:
mode:
authorLukas Reschke <lukas@statuscode.ch>2013-01-29 14:05:54 -0800
committerLukas Reschke <lukas@statuscode.ch>2013-01-29 14:05:54 -0800
commit250c565d2be9ebd7033c43c3362a44c58964c79b (patch)
treef8354bf6b5d6a8a37b46d4685f09342d41dd2695 /lib/user.php
parent472491955ae7e8172b113bd564ec242cc8bc4577 (diff)
parent665979819766bd23cddc18a3e1666f303ac25932 (diff)
downloadnextcloud-server-250c565d2be9ebd7033c43c3362a44c58964c79b.tar.gz
nextcloud-server-250c565d2be9ebd7033c43c3362a44c58964c79b.zip
Merge pull request #1360 from owncloud/display_name
introduction of display names
Diffstat (limited to 'lib/user.php')
-rw-r--r--lib/user.php76
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)