diff options
author | Bjoern Schiessle <bjoern@schiessle.org> | 2017-06-20 13:02:34 +0300 |
---|---|---|
committer | Bjoern Schiessle <bjoern@schiessle.org> | 2017-06-20 13:02:34 +0300 |
commit | 7ec825e8021a00d5f4c5b2b8fb07e8d6239c12a4 (patch) | |
tree | 5099dc6c0548123b6bc7eb9a70d6fcd9a8a3ecda | |
parent | 98e8f448626a62aba037c6fec61083c539218b2f (diff) |
allow the global site selector to search one specific user across all user data
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
-rw-r--r-- | server/lib/UserManager.php | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/server/lib/UserManager.php b/server/lib/UserManager.php index 1ad85ba..cf04e40 100644 --- a/server/lib/UserManager.php +++ b/server/lib/UserManager.php @@ -64,16 +64,17 @@ class UserManager { } $search = $params['search']; - $searchCloudId = $params['exactCloudId']; + $searchCloudId = isset($params['exactCloudId']) ? $params['exactCloudId'] : '0'; + $gssSearch = isset($params['gss']) ? $params['gss'] : '0'; if ($searchCloudId === '1') { - $user = $this->getExactCloudId($search); - $response->getBody()->write(json_encode($user)); - return $response; - } - - if ($this->globalScaleMode === true) { + $users = $this->getExactCloudId($search); + } else if ($gssSearch === '1') { + // lookup request from a global site selector to login the user + $users = $this->gssLookup($search); + } else if ($this->globalScaleMode === true) { // in a global scale setup we ignore the karma + // this is used to find people you want to share with $users = $this->searchNoKarma(); } else { $users = $this->searchKarma(); @@ -84,6 +85,7 @@ class UserManager { } /** + * search user, for example to share with them * return all results with karma >= 1 * * @param $search @@ -123,7 +125,10 @@ LIMIT 50'); /** + * search user, for example to share with them * return all results, ignoring the karma + * in a global scale setup we assume that all + * entries are trustworthy * * @param $search * @return array @@ -155,6 +160,31 @@ FROM `store` return $users; } + /** + * find the user who want to login in a global scale setup + * we return the first exact match + * + * @param $search + * @return array + */ + private function gssLookup($search) { + $stmt = $this->db->prepare('SELECT * FROM `store` WHERE v = :search LIMIT 1'); + $stmt->bindParam(':search', $search, \PDO::PARAM_STR); + $stmt->execute(); + + $data = $stmt->fetch(); + $stmt->closeCursor(); + + $user = []; + + if (isset($data['userId'])) { + $user = $this->getForUserId((int)$data['userId']); + } + + return $user; + } + + private function getExactCloudId($cloudId) { $stmt = $this->db->prepare('SELECT id FROM users WHERE federationId = :id'); $stmt->bindParam(':id', $cloudId); |