diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-11-30 13:57:54 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-12-02 09:14:41 +0100 |
commit | df6fc6cc70ceb06e0b9d8a7ff9ce4cbf2f74e710 (patch) | |
tree | 37679559a66256e7d3457d5a93d2534d2e34aa44 /lib/private | |
parent | 7c8a84e7ac31a0f4c1d59ad1c13ca0c5cce65d8e (diff) | |
download | nextcloud-server-df6fc6cc70ceb06e0b9d8a7ff9ce4cbf2f74e710.tar.gz nextcloud-server-df6fc6cc70ceb06e0b9d8a7ff9ce4cbf2f74e710.zip |
Add the user's cloud id to the vCard
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/user/user.php | 67 |
1 files changed, 42 insertions, 25 deletions
diff --git a/lib/private/user/user.php b/lib/private/user/user.php index 023fc5f5a32..ca79f12469c 100644 --- a/lib/private/user/user.php +++ b/lib/private/user/user.php @@ -32,60 +32,48 @@ namespace OC\User; use OC\Hooks\Emitter; use OCP\IAvatarManager; use OCP\IImage; +use OCP\IURLGenerator; use OCP\IUser; use OCP\IConfig; class User implements IUser { - /** - * @var string $uid - */ + /** @var string $uid */ private $uid; - /** - * @var string $displayName - */ + /** @var string $displayName */ private $displayName; - /** - * @var \OC_User_Interface $backend - */ + /** @var \OC_User_Interface $backend */ private $backend; - /** - * @var bool $enabled - */ + /** @var bool $enabled */ private $enabled; - /** - * @var Emitter|Manager $emitter - */ + /** @var Emitter|Manager $emitter */ private $emitter; - /** - * @var string $home - */ + /** @var string $home */ private $home; - /** - * @var int $lastLogin - */ + /** @var int $lastLogin */ private $lastLogin; - /** - * @var \OCP\IConfig $config - */ + /** @var \OCP\IConfig $config */ private $config; /** @var IAvatarManager */ private $avatarManager; + /** @var IURLGenerator */ + private $urlGenerator; + /** * @param string $uid * @param \OC_User_Interface $backend * @param \OC\Hooks\Emitter $emitter * @param \OCP\IConfig $config */ - public function __construct($uid, $backend, $emitter = null, IConfig $config = null, $avatarManager = null) { + public function __construct($uid, $backend, $emitter = null, IConfig $config = null, $avatarManager = null, $urlGenerator = null) { $this->uid = $uid; $this->backend = $backend; $this->emitter = $emitter; @@ -102,6 +90,9 @@ class User implements IUser { if (is_null($this->avatarManager)) { $this->avatarManager = \OC::$server->getAvatarManager(); } + if (is_null($this->urlGenerator)) { + $this->urlGenerator = \OC::$server->getURLGenerator(); + } } /** @@ -342,4 +333,30 @@ class User implements IUser { return null; } + + /** + * get the federation cloud id + * + * @return string + * @since 9.0.0 + */ + public function getCloudId() { + $uid = $this->getUID(); + $server = $this->urlGenerator->getAbsoluteURL('/'); + return $uid . '@' . rtrim( $this->removeProtocolFromUrl($server), '/'); + } + + /** + * @param string $url + * @return string + */ + private function removeProtocolFromUrl($url) { + if (strpos($url, 'https://') === 0) { + return substr($url, strlen('https://')); + } else if (strpos($url, 'http://') === 0) { + return substr($url, strlen('http://')); + } + + return $url; + } } |