| @@ -39,257 +39,257 @@ | ||
| 39 | 39 | |
| 40 | 40 |  class VerifyUserData extends Job { | 
| 41 | 41 | |
| 42 | - /** @var bool */ | |
| 43 | - private $retainJob = true; | |
| 44 | - | |
| 45 | - /** @var int max number of attempts to send the request */ | |
| 46 | - private $maxTry = 24; | |
| 47 | - | |
| 48 | - /** @var int how much time should be between two tries (1 hour) */ | |
| 49 | - private $interval = 3600; | |
| 50 | - | |
| 51 | - /** @var AccountManager */ | |
| 52 | - private $accountManager; | |
| 53 | - | |
| 54 | - /** @var IUserManager */ | |
| 55 | - private $userManager; | |
| 56 | - | |
| 57 | - /** @var IClientService */ | |
| 58 | - private $httpClientService; | |
| 59 | - | |
| 60 | - /** @var ILogger */ | |
| 61 | - private $logger; | |
| 62 | - | |
| 63 | - /** @var string */ | |
| 64 | - private $lookupServerUrl; | |
| 65 | - | |
| 66 | - /** | |
| 67 | - * VerifyUserData constructor. | |
| 68 | - * | |
| 69 | - * @param AccountManager $accountManager | |
| 70 | - * @param IUserManager $userManager | |
| 71 | - * @param IClientService $clientService | |
| 72 | - * @param ILogger $logger | |
| 73 | - * @param IConfig $config | |
| 74 | - */ | |
| 75 | - public function __construct(AccountManager $accountManager, | |
| 76 | - IUserManager $userManager, | |
| 77 | - IClientService $clientService, | |
| 78 | - ILogger $logger, | |
| 79 | - IConfig $config | |
| 80 | -	) { | |
| 81 | - $this->accountManager = $accountManager; | |
| 82 | - $this->userManager = $userManager; | |
| 83 | - $this->httpClientService = $clientService; | |
| 84 | - $this->logger = $logger; | |
| 85 | - | |
| 86 | -		$lookupServerUrl = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); | |
| 87 | - $this->lookupServerUrl = rtrim($lookupServerUrl, '/'); | |
| 88 | - } | |
| 89 | - | |
| 90 | - /** | |
| 91 | - * run the job, then remove it from the jobList | |
| 92 | - * | |
| 93 | - * @param JobList $jobList | |
| 94 | - * @param ILogger|null $logger | |
| 95 | - */ | |
| 96 | -	public function execute($jobList, ILogger $logger = null) { | |
| 97 | - | |
| 98 | -		if ($this->shouldRun($this->argument)) { | |
| 99 | - parent::execute($jobList, $logger); | |
| 100 | - $jobList->remove($this, $this->argument); | |
| 101 | -			if ($this->retainJob) { | |
| 102 | - $this->reAddJob($jobList, $this->argument); | |
| 103 | -			} else { | |
| 104 | - $this->resetVerificationState(); | |
| 105 | - } | |
| 106 | - } | |
| 107 | - | |
| 108 | - } | |
| 109 | - | |
| 110 | -	protected function run($argument) { | |
| 111 | - | |
| 112 | - $try = (int)$argument['try'] + 1; | |
| 113 | - | |
| 114 | -		switch($argument['type']) { | |
| 115 | - case AccountManager::PROPERTY_WEBSITE: | |
| 116 | - $result = $this->verifyWebsite($argument); | |
| 117 | - break; | |
| 118 | - case AccountManager::PROPERTY_TWITTER: | |
| 119 | - case AccountManager::PROPERTY_EMAIL: | |
| 120 | - $result = $this->verifyViaLookupServer($argument, $argument['type']); | |
| 121 | - break; | |
| 122 | - default: | |
| 123 | - // no valid type given, no need to retry | |
| 124 | - $this->logger->error($argument['type'] . ' is no valid type for user account data.'); | |
| 125 | - $result = true; | |
| 126 | - } | |
| 127 | - | |
| 128 | -		if ($result === true || $try > $this->maxTry) { | |
| 129 | - $this->retainJob = false; | |
| 130 | - } | |
| 131 | - } | |
| 132 | - | |
| 133 | - /** | |
| 134 | - * verify web page | |
| 135 | - * | |
| 136 | - * @param array $argument | |
| 137 | - * @return bool true if we could check the verification code, otherwise false | |
| 138 | - */ | |
| 139 | -	protected function verifyWebsite(array $argument) { | |
| 140 | - | |
| 141 | - $result = false; | |
| 142 | - | |
| 143 | - $url = rtrim($argument['data'], '/') . '/.well-known/' . 'CloudIdVerificationCode.txt'; | |
| 144 | - | |
| 145 | - $client = $this->httpClientService->newClient(); | |
| 146 | -		try { | |
| 147 | - $response = $client->get($url); | |
| 148 | -		} catch (\Exception $e) { | |
| 149 | - return false; | |
| 150 | - } | |
| 151 | - | |
| 152 | -		if ($response->getStatusCode() === Http::STATUS_OK) { | |
| 153 | - $result = true; | |
| 154 | - $publishedCode = $response->getBody(); | |
| 155 | - // remove new lines and spaces | |
| 156 | -			$publishedCodeSanitized = trim(preg_replace('/\s\s+/', ' ', $publishedCode)); | |
| 157 | - $user = $this->userManager->get($argument['uid']); | |
| 158 | - // we don't check a valid user -> give up | |
| 159 | -			if ($user === null) { | |
| 160 | - $this->logger->error($argument['uid'] . ' doesn\'t exist, can\'t verify user data.'); | |
| 161 | - return $result; | |
| 162 | - } | |
| 163 | - $userData = $this->accountManager->getUser($user); | |
| 164 | - | |
| 165 | -			if ($publishedCodeSanitized === $argument['verificationCode']) { | |
| 166 | - $userData[AccountManager::PROPERTY_WEBSITE]['verified'] = AccountManager::VERIFIED; | |
| 167 | -			} else { | |
| 168 | - $userData[AccountManager::PROPERTY_WEBSITE]['verified'] = AccountManager::NOT_VERIFIED; | |
| 169 | - } | |
| 170 | - | |
| 171 | - $this->accountManager->updateUser($user, $userData); | |
| 172 | - } | |
| 173 | - | |
| 174 | - return $result; | |
| 175 | - } | |
| 176 | - | |
| 177 | - /** | |
| 178 | - * verify email address | |
| 179 | - * | |
| 180 | - * @param array $argument | |
| 181 | - * @param string $dataType | |
| 182 | - * @return bool true if we could check the verification code, otherwise false | |
| 183 | - */ | |
| 184 | -	protected function verifyViaLookupServer(array $argument, $dataType) { | |
| 185 | -		if(empty($this->lookupServerUrl) || $this->config->getSystemValue('has_internet_connection', true) === false) { | |
| 186 | - return false; | |
| 187 | - } | |
| 188 | - | |
| 189 | - $user = $this->userManager->get($argument['uid']); | |
| 190 | - | |
| 191 | - // we don't check a valid user -> give up | |
| 192 | -		if ($user === null) { | |
| 193 | - $this->logger->info($argument['uid'] . ' doesn\'t exist, can\'t verify user data.'); | |
| 194 | - return true; | |
| 195 | - } | |
| 196 | - | |
| 197 | - $localUserData = $this->accountManager->getUser($user); | |
| 198 | - $cloudId = $user->getCloudId(); | |
| 199 | - | |
| 200 | - // ask lookup-server for user data | |
| 201 | - $lookupServerData = $this->queryLookupServer($cloudId); | |
| 202 | - | |
| 203 | - // for some reasons we couldn't read any data from the lookup server, try again later | |
| 204 | -		if (empty($lookupServerData)) { | |
| 205 | - return false; | |
| 206 | - } | |
| 207 | - | |
| 208 | - // lookup server has verification data for wrong user data (e.g. email address), try again later | |
| 209 | -		if ($lookupServerData[$dataType]['value'] !== $argument['data']) { | |
| 210 | - return false; | |
| 211 | - } | |
| 212 | - | |
| 213 | - // lookup server hasn't verified the email address so far, try again later | |
| 214 | -		if ($lookupServerData[$dataType]['verified'] === AccountManager::NOT_VERIFIED) { | |
| 215 | - return false; | |
| 216 | - } | |
| 217 | - | |
| 218 | - $localUserData[$dataType]['verified'] = AccountManager::VERIFIED; | |
| 219 | - $this->accountManager->updateUser($user, $localUserData); | |
| 220 | - | |
| 221 | - return true; | |
| 222 | - } | |
| 223 | - | |
| 224 | - /** | |
| 225 | - * @param string $cloudId | |
| 226 | - * @return array | |
| 227 | - */ | |
| 228 | -	protected function queryLookupServer($cloudId) { | |
| 229 | -		try { | |
| 230 | - $client = $this->httpClientService->newClient(); | |
| 231 | - $response = $client->get( | |
| 232 | - $this->lookupServerUrl . '/users?search=' . urlencode($cloudId) . '&exactCloudId=1', | |
| 233 | - [ | |
| 234 | - 'timeout' => 10, | |
| 235 | - 'connect_timeout' => 3, | |
| 236 | - ] | |
| 237 | - ); | |
| 238 | - | |
| 239 | - $body = json_decode($response->getBody(), true); | |
| 240 | - | |
| 241 | -			if (is_array($body) && isset($body['federationId']) && $body['federationId'] === $cloudId) { | |
| 242 | - return $body; | |
| 243 | - } | |
| 244 | - | |
| 245 | -		} catch (\Exception $e) { | |
| 246 | - // do nothing, we will just re-try later | |
| 247 | - } | |
| 248 | - | |
| 249 | - return []; | |
| 250 | - } | |
| 251 | - | |
| 252 | - /** | |
| 253 | - * re-add background job with new arguments | |
| 254 | - * | |
| 255 | - * @param IJobList $jobList | |
| 256 | - * @param array $argument | |
| 257 | - */ | |
| 258 | -	protected function reAddJob(IJobList $jobList, array $argument) { | |
| 259 | - $jobList->add(VerifyUserData::class, | |
| 260 | - [ | |
| 261 | - 'verificationCode' => $argument['verificationCode'], | |
| 262 | - 'data' => $argument['data'], | |
| 263 | - 'type' => $argument['type'], | |
| 264 | - 'uid' => $argument['uid'], | |
| 265 | - 'try' => (int)$argument['try'] + 1, | |
| 266 | - 'lastRun' => time() | |
| 267 | - ] | |
| 268 | - ); | |
| 269 | - } | |
| 270 | - | |
| 271 | - /** | |
| 272 | - * test if it is time for the next run | |
| 273 | - * | |
| 274 | - * @param array $argument | |
| 275 | - * @return bool | |
| 276 | - */ | |
| 277 | -	protected function shouldRun(array $argument) { | |
| 278 | - $lastRun = (int)$argument['lastRun']; | |
| 279 | - return ((time() - $lastRun) > $this->interval); | |
| 280 | - } | |
| 281 | - | |
| 282 | - | |
| 283 | - /** | |
| 284 | - * reset verification state after max tries are reached | |
| 285 | - */ | |
| 286 | -	protected function resetVerificationState() { | |
| 287 | - $user = $this->userManager->get($this->argument['uid']); | |
| 288 | -		if ($user !== null) { | |
| 289 | - $accountData = $this->accountManager->getUser($user); | |
| 290 | - $accountData[$this->argument['type']]['verified'] = AccountManager::NOT_VERIFIED; | |
| 291 | - $this->accountManager->updateUser($user, $accountData); | |
| 292 | - } | |
| 293 | - } | |
| 42 | + /** @var bool */ | |
| 43 | + private $retainJob = true; | |
| 44 | + | |
| 45 | + /** @var int max number of attempts to send the request */ | |
| 46 | + private $maxTry = 24; | |
| 47 | + | |
| 48 | + /** @var int how much time should be between two tries (1 hour) */ | |
| 49 | + private $interval = 3600; | |
| 50 | + | |
| 51 | + /** @var AccountManager */ | |
| 52 | + private $accountManager; | |
| 53 | + | |
| 54 | + /** @var IUserManager */ | |
| 55 | + private $userManager; | |
| 56 | + | |
| 57 | + /** @var IClientService */ | |
| 58 | + private $httpClientService; | |
| 59 | + | |
| 60 | + /** @var ILogger */ | |
| 61 | + private $logger; | |
| 62 | + | |
| 63 | + /** @var string */ | |
| 64 | + private $lookupServerUrl; | |
| 65 | + | |
| 66 | + /** | |
| 67 | + * VerifyUserData constructor. | |
| 68 | + * | |
| 69 | + * @param AccountManager $accountManager | |
| 70 | + * @param IUserManager $userManager | |
| 71 | + * @param IClientService $clientService | |
| 72 | + * @param ILogger $logger | |
| 73 | + * @param IConfig $config | |
| 74 | + */ | |
| 75 | + public function __construct(AccountManager $accountManager, | |
| 76 | + IUserManager $userManager, | |
| 77 | + IClientService $clientService, | |
| 78 | + ILogger $logger, | |
| 79 | + IConfig $config | |
| 80 | +    ) { | |
| 81 | + $this->accountManager = $accountManager; | |
| 82 | + $this->userManager = $userManager; | |
| 83 | + $this->httpClientService = $clientService; | |
| 84 | + $this->logger = $logger; | |
| 85 | + | |
| 86 | +        $lookupServerUrl = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); | |
| 87 | + $this->lookupServerUrl = rtrim($lookupServerUrl, '/'); | |
| 88 | + } | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * run the job, then remove it from the jobList | |
| 92 | + * | |
| 93 | + * @param JobList $jobList | |
| 94 | + * @param ILogger|null $logger | |
| 95 | + */ | |
| 96 | +    public function execute($jobList, ILogger $logger = null) { | |
| 97 | + | |
| 98 | +        if ($this->shouldRun($this->argument)) { | |
| 99 | + parent::execute($jobList, $logger); | |
| 100 | + $jobList->remove($this, $this->argument); | |
| 101 | +            if ($this->retainJob) { | |
| 102 | + $this->reAddJob($jobList, $this->argument); | |
| 103 | +            } else { | |
| 104 | + $this->resetVerificationState(); | |
| 105 | + } | |
| 106 | + } | |
| 107 | + | |
| 108 | + } | |
| 109 | + | |
| 110 | +    protected function run($argument) { | |
| 111 | + | |
| 112 | + $try = (int)$argument['try'] + 1; | |
| 113 | + | |
| 114 | +        switch($argument['type']) { | |
| 115 | + case AccountManager::PROPERTY_WEBSITE: | |
| 116 | + $result = $this->verifyWebsite($argument); | |
| 117 | + break; | |
| 118 | + case AccountManager::PROPERTY_TWITTER: | |
| 119 | + case AccountManager::PROPERTY_EMAIL: | |
| 120 | + $result = $this->verifyViaLookupServer($argument, $argument['type']); | |
| 121 | + break; | |
| 122 | + default: | |
| 123 | + // no valid type given, no need to retry | |
| 124 | + $this->logger->error($argument['type'] . ' is no valid type for user account data.'); | |
| 125 | + $result = true; | |
| 126 | + } | |
| 127 | + | |
| 128 | +        if ($result === true || $try > $this->maxTry) { | |
| 129 | + $this->retainJob = false; | |
| 130 | + } | |
| 131 | + } | |
| 132 | + | |
| 133 | + /** | |
| 134 | + * verify web page | |
| 135 | + * | |
| 136 | + * @param array $argument | |
| 137 | + * @return bool true if we could check the verification code, otherwise false | |
| 138 | + */ | |
| 139 | +    protected function verifyWebsite(array $argument) { | |
| 140 | + | |
| 141 | + $result = false; | |
| 142 | + | |
| 143 | + $url = rtrim($argument['data'], '/') . '/.well-known/' . 'CloudIdVerificationCode.txt'; | |
| 144 | + | |
| 145 | + $client = $this->httpClientService->newClient(); | |
| 146 | +        try { | |
| 147 | + $response = $client->get($url); | |
| 148 | +        } catch (\Exception $e) { | |
| 149 | + return false; | |
| 150 | + } | |
| 151 | + | |
| 152 | +        if ($response->getStatusCode() === Http::STATUS_OK) { | |
| 153 | + $result = true; | |
| 154 | + $publishedCode = $response->getBody(); | |
| 155 | + // remove new lines and spaces | |
| 156 | +            $publishedCodeSanitized = trim(preg_replace('/\s\s+/', ' ', $publishedCode)); | |
| 157 | + $user = $this->userManager->get($argument['uid']); | |
| 158 | + // we don't check a valid user -> give up | |
| 159 | +            if ($user === null) { | |
| 160 | + $this->logger->error($argument['uid'] . ' doesn\'t exist, can\'t verify user data.'); | |
| 161 | + return $result; | |
| 162 | + } | |
| 163 | + $userData = $this->accountManager->getUser($user); | |
| 164 | + | |
| 165 | +            if ($publishedCodeSanitized === $argument['verificationCode']) { | |
| 166 | + $userData[AccountManager::PROPERTY_WEBSITE]['verified'] = AccountManager::VERIFIED; | |
| 167 | +            } else { | |
| 168 | + $userData[AccountManager::PROPERTY_WEBSITE]['verified'] = AccountManager::NOT_VERIFIED; | |
| 169 | + } | |
| 170 | + | |
| 171 | + $this->accountManager->updateUser($user, $userData); | |
| 172 | + } | |
| 173 | + | |
| 174 | + return $result; | |
| 175 | + } | |
| 176 | + | |
| 177 | + /** | |
| 178 | + * verify email address | |
| 179 | + * | |
| 180 | + * @param array $argument | |
| 181 | + * @param string $dataType | |
| 182 | + * @return bool true if we could check the verification code, otherwise false | |
| 183 | + */ | |
| 184 | +    protected function verifyViaLookupServer(array $argument, $dataType) { | |
| 185 | +        if(empty($this->lookupServerUrl) || $this->config->getSystemValue('has_internet_connection', true) === false) { | |
| 186 | + return false; | |
| 187 | + } | |
| 188 | + | |
| 189 | + $user = $this->userManager->get($argument['uid']); | |
| 190 | + | |
| 191 | + // we don't check a valid user -> give up | |
| 192 | +        if ($user === null) { | |
| 193 | + $this->logger->info($argument['uid'] . ' doesn\'t exist, can\'t verify user data.'); | |
| 194 | + return true; | |
| 195 | + } | |
| 196 | + | |
| 197 | + $localUserData = $this->accountManager->getUser($user); | |
| 198 | + $cloudId = $user->getCloudId(); | |
| 199 | + | |
| 200 | + // ask lookup-server for user data | |
| 201 | + $lookupServerData = $this->queryLookupServer($cloudId); | |
| 202 | + | |
| 203 | + // for some reasons we couldn't read any data from the lookup server, try again later | |
| 204 | +        if (empty($lookupServerData)) { | |
| 205 | + return false; | |
| 206 | + } | |
| 207 | + | |
| 208 | + // lookup server has verification data for wrong user data (e.g. email address), try again later | |
| 209 | +        if ($lookupServerData[$dataType]['value'] !== $argument['data']) { | |
| 210 | + return false; | |
| 211 | + } | |
| 212 | + | |
| 213 | + // lookup server hasn't verified the email address so far, try again later | |
| 214 | +        if ($lookupServerData[$dataType]['verified'] === AccountManager::NOT_VERIFIED) { | |
| 215 | + return false; | |
| 216 | + } | |
| 217 | + | |
| 218 | + $localUserData[$dataType]['verified'] = AccountManager::VERIFIED; | |
| 219 | + $this->accountManager->updateUser($user, $localUserData); | |
| 220 | + | |
| 221 | + return true; | |
| 222 | + } | |
| 223 | + | |
| 224 | + /** | |
| 225 | + * @param string $cloudId | |
| 226 | + * @return array | |
| 227 | + */ | |
| 228 | +    protected function queryLookupServer($cloudId) { | |
| 229 | +        try { | |
| 230 | + $client = $this->httpClientService->newClient(); | |
| 231 | + $response = $client->get( | |
| 232 | + $this->lookupServerUrl . '/users?search=' . urlencode($cloudId) . '&exactCloudId=1', | |
| 233 | + [ | |
| 234 | + 'timeout' => 10, | |
| 235 | + 'connect_timeout' => 3, | |
| 236 | + ] | |
| 237 | + ); | |
| 238 | + | |
| 239 | + $body = json_decode($response->getBody(), true); | |
| 240 | + | |
| 241 | +            if (is_array($body) && isset($body['federationId']) && $body['federationId'] === $cloudId) { | |
| 242 | + return $body; | |
| 243 | + } | |
| 244 | + | |
| 245 | +        } catch (\Exception $e) { | |
| 246 | + // do nothing, we will just re-try later | |
| 247 | + } | |
| 248 | + | |
| 249 | + return []; | |
| 250 | + } | |
| 251 | + | |
| 252 | + /** | |
| 253 | + * re-add background job with new arguments | |
| 254 | + * | |
| 255 | + * @param IJobList $jobList | |
| 256 | + * @param array $argument | |
| 257 | + */ | |
| 258 | +    protected function reAddJob(IJobList $jobList, array $argument) { | |
| 259 | + $jobList->add(VerifyUserData::class, | |
| 260 | + [ | |
| 261 | + 'verificationCode' => $argument['verificationCode'], | |
| 262 | + 'data' => $argument['data'], | |
| 263 | + 'type' => $argument['type'], | |
| 264 | + 'uid' => $argument['uid'], | |
| 265 | + 'try' => (int)$argument['try'] + 1, | |
| 266 | + 'lastRun' => time() | |
| 267 | + ] | |
| 268 | + ); | |
| 269 | + } | |
| 270 | + | |
| 271 | + /** | |
| 272 | + * test if it is time for the next run | |
| 273 | + * | |
| 274 | + * @param array $argument | |
| 275 | + * @return bool | |
| 276 | + */ | |
| 277 | +    protected function shouldRun(array $argument) { | |
| 278 | + $lastRun = (int)$argument['lastRun']; | |
| 279 | + return ((time() - $lastRun) > $this->interval); | |
| 280 | + } | |
| 281 | + | |
| 282 | + | |
| 283 | + /** | |
| 284 | + * reset verification state after max tries are reached | |
| 285 | + */ | |
| 286 | +    protected function resetVerificationState() { | |
| 287 | + $user = $this->userManager->get($this->argument['uid']); | |
| 288 | +        if ($user !== null) { | |
| 289 | + $accountData = $this->accountManager->getUser($user); | |
| 290 | + $accountData[$this->argument['type']]['verified'] = AccountManager::NOT_VERIFIED; | |
| 291 | + $this->accountManager->updateUser($user, $accountData); | |
| 292 | + } | |
| 293 | + } | |
| 294 | 294 | |
| 295 | 295 | } | 
| @@ -109,9 +109,9 @@ discard block | ||
| 109 | 109 | |
| 110 | 110 |  	protected function run($argument) { | 
| 111 | 111 | |
| 112 | - $try = (int)$argument['try'] + 1; | |
| 112 | + $try = (int) $argument['try'] + 1; | |
| 113 | 113 | |
| 114 | -		switch($argument['type']) { | |
| 114 | +		switch ($argument['type']) { | |
| 115 | 115 | case AccountManager::PROPERTY_WEBSITE: | 
| 116 | 116 | $result = $this->verifyWebsite($argument); | 
| 117 | 117 | break; | 
| @@ -121,7 +121,7 @@ discard block | ||
| 121 | 121 | break; | 
| 122 | 122 | default: | 
| 123 | 123 | // no valid type given, no need to retry | 
| 124 | - $this->logger->error($argument['type'] . ' is no valid type for user account data.'); | |
| 124 | + $this->logger->error($argument['type'].' is no valid type for user account data.'); | |
| 125 | 125 | $result = true; | 
| 126 | 126 | } | 
| 127 | 127 | |
| @@ -140,7 +140,7 @@ discard block | ||
| 140 | 140 | |
| 141 | 141 | $result = false; | 
| 142 | 142 | |
| 143 | - $url = rtrim($argument['data'], '/') . '/.well-known/' . 'CloudIdVerificationCode.txt'; | |
| 143 | + $url = rtrim($argument['data'], '/').'/.well-known/'.'CloudIdVerificationCode.txt'; | |
| 144 | 144 | |
| 145 | 145 | $client = $this->httpClientService->newClient(); | 
| 146 | 146 |  		try { | 
| @@ -157,7 +157,7 @@ discard block | ||
| 157 | 157 | $user = $this->userManager->get($argument['uid']); | 
| 158 | 158 | // we don't check a valid user -> give up | 
| 159 | 159 |  			if ($user === null) { | 
| 160 | - $this->logger->error($argument['uid'] . ' doesn\'t exist, can\'t verify user data.'); | |
| 160 | + $this->logger->error($argument['uid'].' doesn\'t exist, can\'t verify user data.'); | |
| 161 | 161 | return $result; | 
| 162 | 162 | } | 
| 163 | 163 | $userData = $this->accountManager->getUser($user); | 
| @@ -182,7 +182,7 @@ discard block | ||
| 182 | 182 | * @return bool true if we could check the verification code, otherwise false | 
| 183 | 183 | */ | 
| 184 | 184 |  	protected function verifyViaLookupServer(array $argument, $dataType) { | 
| 185 | -		if(empty($this->lookupServerUrl) || $this->config->getSystemValue('has_internet_connection', true) === false) { | |
| 185 | +		if (empty($this->lookupServerUrl) || $this->config->getSystemValue('has_internet_connection', true) === false) { | |
| 186 | 186 | return false; | 
| 187 | 187 | } | 
| 188 | 188 | |
| @@ -190,7 +190,7 @@ discard block | ||
| 190 | 190 | |
| 191 | 191 | // we don't check a valid user -> give up | 
| 192 | 192 |  		if ($user === null) { | 
| 193 | - $this->logger->info($argument['uid'] . ' doesn\'t exist, can\'t verify user data.'); | |
| 193 | + $this->logger->info($argument['uid'].' doesn\'t exist, can\'t verify user data.'); | |
| 194 | 194 | return true; | 
| 195 | 195 | } | 
| 196 | 196 | |
| @@ -229,7 +229,7 @@ discard block | ||
| 229 | 229 |  		try { | 
| 230 | 230 | $client = $this->httpClientService->newClient(); | 
| 231 | 231 | $response = $client->get( | 
| 232 | - $this->lookupServerUrl . '/users?search=' . urlencode($cloudId) . '&exactCloudId=1', | |
| 232 | + $this->lookupServerUrl.'/users?search='.urlencode($cloudId).'&exactCloudId=1', | |
| 233 | 233 | [ | 
| 234 | 234 | 'timeout' => 10, | 
| 235 | 235 | 'connect_timeout' => 3, | 
| @@ -262,7 +262,7 @@ discard block | ||
| 262 | 262 | 'data' => $argument['data'], | 
| 263 | 263 | 'type' => $argument['type'], | 
| 264 | 264 | 'uid' => $argument['uid'], | 
| 265 | - 'try' => (int)$argument['try'] + 1, | |
| 265 | + 'try' => (int) $argument['try'] + 1, | |
| 266 | 266 | 'lastRun' => time() | 
| 267 | 267 | ] | 
| 268 | 268 | ); | 
| @@ -275,7 +275,7 @@ discard block | ||
| 275 | 275 | * @return bool | 
| 276 | 276 | */ | 
| 277 | 277 |  	protected function shouldRun(array $argument) { | 
| 278 | - $lastRun = (int)$argument['lastRun']; | |
| 278 | + $lastRun = (int) $argument['lastRun']; | |
| 279 | 279 | return ((time() - $lastRun) > $this->interval); | 
| 280 | 280 | } | 
| 281 | 281 | |
| @@ -30,84 +30,84 @@ | ||
| 30 | 30 | use OCP\ILogger; | 
| 31 | 31 | |
| 32 | 32 |  class RetryJob extends Job { | 
| 33 | - /** @var IClientService */ | |
| 34 | - private $clientService; | |
| 35 | - /** @var IJobList */ | |
| 36 | - private $jobList; | |
| 37 | - /** @var string */ | |
| 38 | - private $lookupServer; | |
| 39 | - /** @var int how much time should be between two tries (10 minutes) */ | |
| 40 | - private $interval = 600; | |
| 33 | + /** @var IClientService */ | |
| 34 | + private $clientService; | |
| 35 | + /** @var IJobList */ | |
| 36 | + private $jobList; | |
| 37 | + /** @var string */ | |
| 38 | + private $lookupServer; | |
| 39 | + /** @var int how much time should be between two tries (10 minutes) */ | |
| 40 | + private $interval = 600; | |
| 41 | 41 | |
| 42 | - /** | |
| 43 | - * @param IClientService $clientService | |
| 44 | - * @param IJobList $jobList | |
| 45 | - * @param IConfig $config | |
| 46 | - */ | |
| 47 | - public function __construct(IClientService $clientService, | |
| 48 | - IJobList $jobList, | |
| 49 | -								IConfig $config) { | |
| 50 | - $this->clientService = $clientService; | |
| 51 | - $this->jobList = $jobList; | |
| 42 | + /** | |
| 43 | + * @param IClientService $clientService | |
| 44 | + * @param IJobList $jobList | |
| 45 | + * @param IConfig $config | |
| 46 | + */ | |
| 47 | + public function __construct(IClientService $clientService, | |
| 48 | + IJobList $jobList, | |
| 49 | +                                IConfig $config) { | |
| 50 | + $this->clientService = $clientService; | |
| 51 | + $this->jobList = $jobList; | |
| 52 | 52 | |
| 53 | -		if ($config->getSystemValue('has_internet_connection', true) === false) { | |
| 54 | - return; | |
| 55 | - } | |
| 53 | +        if ($config->getSystemValue('has_internet_connection', true) === false) { | |
| 54 | + return; | |
| 55 | + } | |
| 56 | 56 | |
| 57 | -		$this->lookupServer = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); | |
| 58 | -		if (!empty($this->lookupServer)) { | |
| 59 | - $this->lookupServer = rtrim($this->lookupServer, '/'); | |
| 60 | - $this->lookupServer .= '/users'; | |
| 61 | - } | |
| 62 | - } | |
| 57 | +        $this->lookupServer = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); | |
| 58 | +        if (!empty($this->lookupServer)) { | |
| 59 | + $this->lookupServer = rtrim($this->lookupServer, '/'); | |
| 60 | + $this->lookupServer .= '/users'; | |
| 61 | + } | |
| 62 | + } | |
| 63 | 63 | |
| 64 | - /** | |
| 65 | - * run the job, then remove it from the jobList | |
| 66 | - * | |
| 67 | - * @param JobList $jobList | |
| 68 | - * @param ILogger|null $logger | |
| 69 | - */ | |
| 70 | -	public function execute($jobList, ILogger $logger = null) { | |
| 71 | -		if ($this->shouldRun($this->argument)) { | |
| 72 | - parent::execute($jobList, $logger); | |
| 73 | - $jobList->remove($this, $this->argument); | |
| 74 | - } | |
| 75 | - } | |
| 64 | + /** | |
| 65 | + * run the job, then remove it from the jobList | |
| 66 | + * | |
| 67 | + * @param JobList $jobList | |
| 68 | + * @param ILogger|null $logger | |
| 69 | + */ | |
| 70 | +    public function execute($jobList, ILogger $logger = null) { | |
| 71 | +        if ($this->shouldRun($this->argument)) { | |
| 72 | + parent::execute($jobList, $logger); | |
| 73 | + $jobList->remove($this, $this->argument); | |
| 74 | + } | |
| 75 | + } | |
| 76 | 76 | |
| 77 | -	protected function run($argument) { | |
| 78 | -		if ($argument['retryNo'] === 5 || empty($this->lookupServer)) { | |
| 79 | - return; | |
| 80 | - } | |
| 77 | +    protected function run($argument) { | |
| 78 | +        if ($argument['retryNo'] === 5 || empty($this->lookupServer)) { | |
| 79 | + return; | |
| 80 | + } | |
| 81 | 81 | |
| 82 | - $client = $this->clientService->newClient(); | |
| 82 | + $client = $this->clientService->newClient(); | |
| 83 | 83 | |
| 84 | -		try { | |
| 85 | - $client->post($this->lookupServer, | |
| 86 | - [ | |
| 87 | - 'body' => json_encode($argument['dataArray']), | |
| 88 | - 'timeout' => 10, | |
| 89 | - 'connect_timeout' => 3, | |
| 90 | - ] | |
| 91 | - ); | |
| 92 | -		} catch (\Exception $e) { | |
| 93 | - $this->jobList->add(RetryJob::class, | |
| 94 | - [ | |
| 95 | - 'dataArray' => $argument['dataArray'], | |
| 96 | - 'retryNo' => $argument['retryNo'] + 1, | |
| 97 | - 'lastRun' => time(), | |
| 98 | - ] | |
| 99 | - ); | |
| 84 | +        try { | |
| 85 | + $client->post($this->lookupServer, | |
| 86 | + [ | |
| 87 | + 'body' => json_encode($argument['dataArray']), | |
| 88 | + 'timeout' => 10, | |
| 89 | + 'connect_timeout' => 3, | |
| 90 | + ] | |
| 91 | + ); | |
| 92 | +        } catch (\Exception $e) { | |
| 93 | + $this->jobList->add(RetryJob::class, | |
| 94 | + [ | |
| 95 | + 'dataArray' => $argument['dataArray'], | |
| 96 | + 'retryNo' => $argument['retryNo'] + 1, | |
| 97 | + 'lastRun' => time(), | |
| 98 | + ] | |
| 99 | + ); | |
| 100 | 100 | |
| 101 | - } | |
| 102 | - } | |
| 101 | + } | |
| 102 | + } | |
| 103 | 103 | |
| 104 | - /** | |
| 105 | - * test if it is time for the next run | |
| 106 | - * | |
| 107 | - * @param array $argument | |
| 108 | - * @return bool | |
| 109 | - */ | |
| 110 | -	protected function shouldRun($argument) { | |
| 111 | - return !isset($argument['lastRun']) || ((time() - $argument['lastRun']) > $this->interval); | |
| 112 | - } | |
| 104 | + /** | |
| 105 | + * test if it is time for the next run | |
| 106 | + * | |
| 107 | + * @param array $argument | |
| 108 | + * @return bool | |
| 109 | + */ | |
| 110 | +    protected function shouldRun($argument) { | |
| 111 | + return !isset($argument['lastRun']) || ((time() - $argument['lastRun']) > $this->interval); | |
| 112 | + } | |
| 113 | 113 | } | 
| @@ -36,118 +36,118 @@ | ||
| 36 | 36 | * @package OCA\LookupServerConnector | 
| 37 | 37 | */ | 
| 38 | 38 |  class UpdateLookupServer { | 
| 39 | - /** @var AccountManager */ | |
| 40 | - private $accountManager; | |
| 41 | - /** @var IClientService */ | |
| 42 | - private $clientService; | |
| 43 | - /** @var Signer */ | |
| 44 | - private $signer; | |
| 45 | - /** @var IJobList */ | |
| 46 | - private $jobList; | |
| 47 | - /** @var string URL point to lookup server */ | |
| 48 | - private $lookupServer; | |
| 39 | + /** @var AccountManager */ | |
| 40 | + private $accountManager; | |
| 41 | + /** @var IClientService */ | |
| 42 | + private $clientService; | |
| 43 | + /** @var Signer */ | |
| 44 | + private $signer; | |
| 45 | + /** @var IJobList */ | |
| 46 | + private $jobList; | |
| 47 | + /** @var string URL point to lookup server */ | |
| 48 | + private $lookupServer; | |
| 49 | 49 | |
| 50 | - /** | |
| 51 | - * @param AccountManager $accountManager | |
| 52 | - * @param IClientService $clientService | |
| 53 | - * @param Signer $signer | |
| 54 | - * @param IJobList $jobList | |
| 55 | - * @param IConfig $config | |
| 56 | - */ | |
| 57 | - public function __construct(AccountManager $accountManager, | |
| 58 | - IClientService $clientService, | |
| 59 | - Signer $signer, | |
| 60 | - IJobList $jobList, | |
| 61 | -								IConfig $config) { | |
| 62 | - $this->accountManager = $accountManager; | |
| 63 | - $this->clientService = $clientService; | |
| 64 | - $this->signer = $signer; | |
| 65 | - $this->jobList = $jobList; | |
| 50 | + /** | |
| 51 | + * @param AccountManager $accountManager | |
| 52 | + * @param IClientService $clientService | |
| 53 | + * @param Signer $signer | |
| 54 | + * @param IJobList $jobList | |
| 55 | + * @param IConfig $config | |
| 56 | + */ | |
| 57 | + public function __construct(AccountManager $accountManager, | |
| 58 | + IClientService $clientService, | |
| 59 | + Signer $signer, | |
| 60 | + IJobList $jobList, | |
| 61 | +                                IConfig $config) { | |
| 62 | + $this->accountManager = $accountManager; | |
| 63 | + $this->clientService = $clientService; | |
| 64 | + $this->signer = $signer; | |
| 65 | + $this->jobList = $jobList; | |
| 66 | 66 | |
| 67 | -		if($config->getSystemValue('has_internet_connection', true) === false) { | |
| 68 | - return; | |
| 69 | - } | |
| 67 | +        if($config->getSystemValue('has_internet_connection', true) === false) { | |
| 68 | + return; | |
| 69 | + } | |
| 70 | 70 | |
| 71 | -		$this->lookupServer = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); | |
| 72 | -		if(!empty($this->lookupServer)) { | |
| 73 | - $this->lookupServer = rtrim($this->lookupServer, '/'); | |
| 74 | - $this->lookupServer .= '/users'; | |
| 75 | - } | |
| 76 | - } | |
| 71 | +        $this->lookupServer = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); | |
| 72 | +        if(!empty($this->lookupServer)) { | |
| 73 | + $this->lookupServer = rtrim($this->lookupServer, '/'); | |
| 74 | + $this->lookupServer .= '/users'; | |
| 75 | + } | |
| 76 | + } | |
| 77 | 77 | |
| 78 | - /** | |
| 79 | - * @param IUser $user | |
| 80 | - */ | |
| 81 | -	public function userUpdated(IUser $user) { | |
| 82 | -		if(empty($this->lookupServer)) { | |
| 83 | - return; | |
| 84 | - } | |
| 78 | + /** | |
| 79 | + * @param IUser $user | |
| 80 | + */ | |
| 81 | +    public function userUpdated(IUser $user) { | |
| 82 | +        if(empty($this->lookupServer)) { | |
| 83 | + return; | |
| 84 | + } | |
| 85 | 85 | |
| 86 | - $userData = $this->accountManager->getUser($user); | |
| 87 | - $publicData = []; | |
| 86 | + $userData = $this->accountManager->getUser($user); | |
| 87 | + $publicData = []; | |
| 88 | 88 | |
| 89 | -		foreach ($userData as $key => $data) { | |
| 90 | -			if ($data['scope'] === AccountManager::VISIBILITY_PUBLIC) { | |
| 91 | - $publicData[$key] = $data; | |
| 92 | - } | |
| 93 | - } | |
| 89 | +        foreach ($userData as $key => $data) { | |
| 90 | +            if ($data['scope'] === AccountManager::VISIBILITY_PUBLIC) { | |
| 91 | + $publicData[$key] = $data; | |
| 92 | + } | |
| 93 | + } | |
| 94 | 94 | |
| 95 | - $this->sendToLookupServer($user, $publicData); | |
| 96 | - } | |
| 95 | + $this->sendToLookupServer($user, $publicData); | |
| 96 | + } | |
| 97 | 97 | |
| 98 | - /** | |
| 99 | - * send public user data to the lookup server | |
| 100 | - * | |
| 101 | - * @param IUser $user | |
| 102 | - * @param array $publicData | |
| 103 | - */ | |
| 104 | -	protected function sendToLookupServer(IUser $user, array $publicData) { | |
| 98 | + /** | |
| 99 | + * send public user data to the lookup server | |
| 100 | + * | |
| 101 | + * @param IUser $user | |
| 102 | + * @param array $publicData | |
| 103 | + */ | |
| 104 | +    protected function sendToLookupServer(IUser $user, array $publicData) { | |
| 105 | 105 | |
| 106 | - $dataArray = ['federationId' => $user->getCloudId()]; | |
| 106 | + $dataArray = ['federationId' => $user->getCloudId()]; | |
| 107 | 107 | |
| 108 | -		if (!empty($publicData)) { | |
| 109 | - $dataArray['name'] = isset($publicData[AccountManager::PROPERTY_DISPLAYNAME]) ? $publicData[AccountManager::PROPERTY_DISPLAYNAME]['value'] : ''; | |
| 110 | - $dataArray['email'] = isset($publicData[AccountManager::PROPERTY_EMAIL]) ? $publicData[AccountManager::PROPERTY_EMAIL]['value'] : ''; | |
| 111 | - $dataArray['address'] = isset($publicData[AccountManager::PROPERTY_ADDRESS]) ? $publicData[AccountManager::PROPERTY_ADDRESS]['value'] : ''; | |
| 112 | - $dataArray['website'] = isset($publicData[AccountManager::PROPERTY_WEBSITE]) ? $publicData[AccountManager::PROPERTY_WEBSITE]['value'] : ''; | |
| 113 | - $dataArray['twitter'] = isset($publicData[AccountManager::PROPERTY_TWITTER]) ? $publicData[AccountManager::PROPERTY_TWITTER]['value'] : ''; | |
| 114 | - $dataArray['phone'] = isset($publicData[AccountManager::PROPERTY_PHONE]) ? $publicData[AccountManager::PROPERTY_PHONE]['value'] : ''; | |
| 115 | - $dataArray['twitter_signature'] = isset($publicData[AccountManager::PROPERTY_TWITTER]['signature']) ? $publicData[AccountManager::PROPERTY_TWITTER]['signature'] : ''; | |
| 116 | - $dataArray['website_signature'] = isset($publicData[AccountManager::PROPERTY_WEBSITE]['signature']) ? $publicData[AccountManager::PROPERTY_WEBSITE]['signature'] : ''; | |
| 117 | - $dataArray['verificationStatus'] = | |
| 118 | - [ | |
| 119 | - AccountManager::PROPERTY_WEBSITE => isset($publicData[AccountManager::PROPERTY_WEBSITE]) ? $publicData[AccountManager::PROPERTY_WEBSITE]['verified'] : '', | |
| 120 | - AccountManager::PROPERTY_TWITTER => isset($publicData[AccountManager::PROPERTY_TWITTER]) ? $publicData[AccountManager::PROPERTY_TWITTER]['verified'] : '', | |
| 121 | - ]; | |
| 122 | - } | |
| 108 | +        if (!empty($publicData)) { | |
| 109 | + $dataArray['name'] = isset($publicData[AccountManager::PROPERTY_DISPLAYNAME]) ? $publicData[AccountManager::PROPERTY_DISPLAYNAME]['value'] : ''; | |
| 110 | + $dataArray['email'] = isset($publicData[AccountManager::PROPERTY_EMAIL]) ? $publicData[AccountManager::PROPERTY_EMAIL]['value'] : ''; | |
| 111 | + $dataArray['address'] = isset($publicData[AccountManager::PROPERTY_ADDRESS]) ? $publicData[AccountManager::PROPERTY_ADDRESS]['value'] : ''; | |
| 112 | + $dataArray['website'] = isset($publicData[AccountManager::PROPERTY_WEBSITE]) ? $publicData[AccountManager::PROPERTY_WEBSITE]['value'] : ''; | |
| 113 | + $dataArray['twitter'] = isset($publicData[AccountManager::PROPERTY_TWITTER]) ? $publicData[AccountManager::PROPERTY_TWITTER]['value'] : ''; | |
| 114 | + $dataArray['phone'] = isset($publicData[AccountManager::PROPERTY_PHONE]) ? $publicData[AccountManager::PROPERTY_PHONE]['value'] : ''; | |
| 115 | + $dataArray['twitter_signature'] = isset($publicData[AccountManager::PROPERTY_TWITTER]['signature']) ? $publicData[AccountManager::PROPERTY_TWITTER]['signature'] : ''; | |
| 116 | + $dataArray['website_signature'] = isset($publicData[AccountManager::PROPERTY_WEBSITE]['signature']) ? $publicData[AccountManager::PROPERTY_WEBSITE]['signature'] : ''; | |
| 117 | + $dataArray['verificationStatus'] = | |
| 118 | + [ | |
| 119 | + AccountManager::PROPERTY_WEBSITE => isset($publicData[AccountManager::PROPERTY_WEBSITE]) ? $publicData[AccountManager::PROPERTY_WEBSITE]['verified'] : '', | |
| 120 | + AccountManager::PROPERTY_TWITTER => isset($publicData[AccountManager::PROPERTY_TWITTER]) ? $publicData[AccountManager::PROPERTY_TWITTER]['verified'] : '', | |
| 121 | + ]; | |
| 122 | + } | |
| 123 | 123 | |
| 124 | -		$dataArray = $this->signer->sign('lookupserver', $dataArray, $user); | |
| 125 | - $httpClient = $this->clientService->newClient(); | |
| 126 | -		try { | |
| 127 | -			if (empty($publicData)) { | |
| 128 | - $httpClient->delete($this->lookupServer, | |
| 129 | - [ | |
| 130 | - 'body' => json_encode($dataArray), | |
| 131 | - 'timeout' => 10, | |
| 132 | - 'connect_timeout' => 3, | |
| 133 | - ] | |
| 134 | - ); | |
| 135 | -			} else { | |
| 136 | - $httpClient->post($this->lookupServer, | |
| 137 | - [ | |
| 138 | - 'body' => json_encode($dataArray), | |
| 139 | - 'timeout' => 10, | |
| 140 | - 'connect_timeout' => 3, | |
| 141 | - ] | |
| 142 | - ); | |
| 143 | - } | |
| 144 | -		} catch (\Exception $e) { | |
| 145 | - $this->jobList->add(RetryJob::class, | |
| 146 | - [ | |
| 147 | - 'dataArray' => $dataArray, | |
| 148 | - 'retryNo' => 0, | |
| 149 | - ] | |
| 150 | - ); | |
| 151 | - } | |
| 152 | - } | |
| 124 | +        $dataArray = $this->signer->sign('lookupserver', $dataArray, $user); | |
| 125 | + $httpClient = $this->clientService->newClient(); | |
| 126 | +        try { | |
| 127 | +            if (empty($publicData)) { | |
| 128 | + $httpClient->delete($this->lookupServer, | |
| 129 | + [ | |
| 130 | + 'body' => json_encode($dataArray), | |
| 131 | + 'timeout' => 10, | |
| 132 | + 'connect_timeout' => 3, | |
| 133 | + ] | |
| 134 | + ); | |
| 135 | +            } else { | |
| 136 | + $httpClient->post($this->lookupServer, | |
| 137 | + [ | |
| 138 | + 'body' => json_encode($dataArray), | |
| 139 | + 'timeout' => 10, | |
| 140 | + 'connect_timeout' => 3, | |
| 141 | + ] | |
| 142 | + ); | |
| 143 | + } | |
| 144 | +        } catch (\Exception $e) { | |
| 145 | + $this->jobList->add(RetryJob::class, | |
| 146 | + [ | |
| 147 | + 'dataArray' => $dataArray, | |
| 148 | + 'retryNo' => 0, | |
| 149 | + ] | |
| 150 | + ); | |
| 151 | + } | |
| 152 | + } | |
| 153 | 153 | } | 
| @@ -64,12 +64,12 @@ discard block | ||
| 64 | 64 | $this->signer = $signer; | 
| 65 | 65 | $this->jobList = $jobList; | 
| 66 | 66 | |
| 67 | -		if($config->getSystemValue('has_internet_connection', true) === false) { | |
| 67 | +		if ($config->getSystemValue('has_internet_connection', true) === false) { | |
| 68 | 68 | return; | 
| 69 | 69 | } | 
| 70 | 70 | |
| 71 | 71 |  		$this->lookupServer = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); | 
| 72 | -		if(!empty($this->lookupServer)) { | |
| 72 | +		if (!empty($this->lookupServer)) { | |
| 73 | 73 | $this->lookupServer = rtrim($this->lookupServer, '/'); | 
| 74 | 74 | $this->lookupServer .= '/users'; | 
| 75 | 75 | } | 
| @@ -79,7 +79,7 @@ discard block | ||
| 79 | 79 | * @param IUser $user | 
| 80 | 80 | */ | 
| 81 | 81 |  	public function userUpdated(IUser $user) { | 
| 82 | -		if(empty($this->lookupServer)) { | |
| 82 | +		if (empty($this->lookupServer)) { | |
| 83 | 83 | return; | 
| 84 | 84 | } | 
| 85 | 85 | |
| @@ -36,87 +36,87 @@ | ||
| 36 | 36 | |
| 37 | 37 |  class LookupPlugin implements ISearchPlugin { | 
| 38 | 38 | |
| 39 | - /** @var IConfig */ | |
| 40 | - private $config; | |
| 41 | - /** @var IClientService */ | |
| 42 | - private $clientService; | |
| 43 | - /** @var string remote part of the current user's cloud id */ | |
| 44 | - private $currentUserRemote; | |
| 45 | - /** @var ICloudIdManager */ | |
| 46 | - private $cloudIdManager; | |
| 47 | - /** @var ILogger */ | |
| 48 | - private $logger; | |
| 39 | + /** @var IConfig */ | |
| 40 | + private $config; | |
| 41 | + /** @var IClientService */ | |
| 42 | + private $clientService; | |
| 43 | + /** @var string remote part of the current user's cloud id */ | |
| 44 | + private $currentUserRemote; | |
| 45 | + /** @var ICloudIdManager */ | |
| 46 | + private $cloudIdManager; | |
| 47 | + /** @var ILogger */ | |
| 48 | + private $logger; | |
| 49 | 49 | |
| 50 | - public function __construct(IConfig $config, | |
| 51 | - IClientService $clientService, | |
| 52 | - IUserSession $userSession, | |
| 53 | - ICloudIdManager $cloudIdManager, | |
| 54 | -								ILogger $logger) { | |
| 55 | - $this->config = $config; | |
| 56 | - $this->clientService = $clientService; | |
| 57 | - $this->cloudIdManager = $cloudIdManager; | |
| 58 | - $currentUserCloudId = $userSession->getUser()->getCloudId(); | |
| 59 | - $this->currentUserRemote = $cloudIdManager->resolveCloudId($currentUserCloudId)->getRemote(); | |
| 60 | - $this->logger = $logger; | |
| 61 | - } | |
| 50 | + public function __construct(IConfig $config, | |
| 51 | + IClientService $clientService, | |
| 52 | + IUserSession $userSession, | |
| 53 | + ICloudIdManager $cloudIdManager, | |
| 54 | +                                ILogger $logger) { | |
| 55 | + $this->config = $config; | |
| 56 | + $this->clientService = $clientService; | |
| 57 | + $this->cloudIdManager = $cloudIdManager; | |
| 58 | + $currentUserCloudId = $userSession->getUser()->getCloudId(); | |
| 59 | + $this->currentUserRemote = $cloudIdManager->resolveCloudId($currentUserCloudId)->getRemote(); | |
| 60 | + $this->logger = $logger; | |
| 61 | + } | |
| 62 | 62 | |
| 63 | -	public function search($search, $limit, $offset, ISearchResult $searchResult) { | |
| 64 | -		$isGlobalScaleEnabled = $this->config->getSystemValue('gs.enabled', false); | |
| 65 | -		$isLookupServerEnabled = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') === 'yes'; | |
| 66 | -		$hasInternetConnection = (bool)$this->config->getSystemValue('has_internet_connection', true); | |
| 63 | +    public function search($search, $limit, $offset, ISearchResult $searchResult) { | |
| 64 | +        $isGlobalScaleEnabled = $this->config->getSystemValue('gs.enabled', false); | |
| 65 | +        $isLookupServerEnabled = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') === 'yes'; | |
| 66 | +        $hasInternetConnection = (bool)$this->config->getSystemValue('has_internet_connection', true); | |
| 67 | 67 | |
| 68 | - // if case of Global Scale we always search the lookup server | |
| 69 | -		if ((!$isLookupServerEnabled && !$isGlobalScaleEnabled) || !$hasInternetConnection) { | |
| 70 | - return false; | |
| 71 | - } | |
| 68 | + // if case of Global Scale we always search the lookup server | |
| 69 | +        if ((!$isLookupServerEnabled && !$isGlobalScaleEnabled) || !$hasInternetConnection) { | |
| 70 | + return false; | |
| 71 | + } | |
| 72 | 72 | |
| 73 | -		$lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); | |
| 74 | -		if(empty($lookupServerUrl)) { | |
| 75 | - return false; | |
| 76 | - } | |
| 77 | - $lookupServerUrl = rtrim($lookupServerUrl, '/'); | |
| 78 | - $result = []; | |
| 73 | +        $lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); | |
| 74 | +        if(empty($lookupServerUrl)) { | |
| 75 | + return false; | |
| 76 | + } | |
| 77 | + $lookupServerUrl = rtrim($lookupServerUrl, '/'); | |
| 78 | + $result = []; | |
| 79 | 79 | |
| 80 | -		try { | |
| 81 | - $client = $this->clientService->newClient(); | |
| 82 | - $response = $client->get( | |
| 83 | - $lookupServerUrl . '/users?search=' . urlencode($search), | |
| 84 | - [ | |
| 85 | - 'timeout' => 10, | |
| 86 | - 'connect_timeout' => 3, | |
| 87 | - ] | |
| 88 | - ); | |
| 80 | +        try { | |
| 81 | + $client = $this->clientService->newClient(); | |
| 82 | + $response = $client->get( | |
| 83 | + $lookupServerUrl . '/users?search=' . urlencode($search), | |
| 84 | + [ | |
| 85 | + 'timeout' => 10, | |
| 86 | + 'connect_timeout' => 3, | |
| 87 | + ] | |
| 88 | + ); | |
| 89 | 89 | |
| 90 | - $body = json_decode($response->getBody(), true); | |
| 90 | + $body = json_decode($response->getBody(), true); | |
| 91 | 91 | |
| 92 | -			foreach ($body as $lookup) { | |
| 93 | -				try { | |
| 94 | - $remote = $this->cloudIdManager->resolveCloudId($lookup['federationId'])->getRemote(); | |
| 95 | -				} catch (\Exception $e) { | |
| 96 | -					$this->logger->error('Can not parse federated cloud ID "' .  $lookup['federationId'] . '"'); | |
| 97 | - $this->logger->error($e->getMessage()); | |
| 98 | - continue; | |
| 99 | - } | |
| 100 | -				if ($this->currentUserRemote === $remote) { | |
| 101 | - continue; | |
| 102 | - } | |
| 103 | - $name = isset($lookup['name']['value']) ? $lookup['name']['value'] : ''; | |
| 104 | -				$label = empty($name) ? $lookup['federationId'] : $name . ' (' . $lookup['federationId'] . ')'; | |
| 105 | - $result[] = [ | |
| 106 | - 'label' => $label, | |
| 107 | - 'value' => [ | |
| 108 | - 'shareType' => Share::SHARE_TYPE_REMOTE, | |
| 109 | - 'shareWith' => $lookup['federationId'], | |
| 110 | - ], | |
| 111 | - 'extra' => $lookup, | |
| 112 | - ]; | |
| 113 | - } | |
| 114 | -		} catch (\Exception $e) { | |
| 115 | - } | |
| 92 | +            foreach ($body as $lookup) { | |
| 93 | +                try { | |
| 94 | + $remote = $this->cloudIdManager->resolveCloudId($lookup['federationId'])->getRemote(); | |
| 95 | +                } catch (\Exception $e) { | |
| 96 | +                    $this->logger->error('Can not parse federated cloud ID "' .  $lookup['federationId'] . '"'); | |
| 97 | + $this->logger->error($e->getMessage()); | |
| 98 | + continue; | |
| 99 | + } | |
| 100 | +                if ($this->currentUserRemote === $remote) { | |
| 101 | + continue; | |
| 102 | + } | |
| 103 | + $name = isset($lookup['name']['value']) ? $lookup['name']['value'] : ''; | |
| 104 | +                $label = empty($name) ? $lookup['federationId'] : $name . ' (' . $lookup['federationId'] . ')'; | |
| 105 | + $result[] = [ | |
| 106 | + 'label' => $label, | |
| 107 | + 'value' => [ | |
| 108 | + 'shareType' => Share::SHARE_TYPE_REMOTE, | |
| 109 | + 'shareWith' => $lookup['federationId'], | |
| 110 | + ], | |
| 111 | + 'extra' => $lookup, | |
| 112 | + ]; | |
| 113 | + } | |
| 114 | +        } catch (\Exception $e) { | |
| 115 | + } | |
| 116 | 116 | |
| 117 | -		$type = new SearchResultType('lookup'); | |
| 118 | - $searchResult->addResultSet($type, $result, []); | |
| 117 | +        $type = new SearchResultType('lookup'); | |
| 118 | + $searchResult->addResultSet($type, $result, []); | |
| 119 | 119 | |
| 120 | - return false; | |
| 121 | - } | |
| 120 | + return false; | |
| 121 | + } | |
| 122 | 122 | } | 
| @@ -63,7 +63,7 @@ discard block | ||
| 63 | 63 |  	public function search($search, $limit, $offset, ISearchResult $searchResult) { | 
| 64 | 64 |  		$isGlobalScaleEnabled = $this->config->getSystemValue('gs.enabled', false); | 
| 65 | 65 |  		$isLookupServerEnabled = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') === 'yes'; | 
| 66 | -		$hasInternetConnection = (bool)$this->config->getSystemValue('has_internet_connection', true); | |
| 66 | +		$hasInternetConnection = (bool) $this->config->getSystemValue('has_internet_connection', true); | |
| 67 | 67 | |
| 68 | 68 | // if case of Global Scale we always search the lookup server | 
| 69 | 69 |  		if ((!$isLookupServerEnabled && !$isGlobalScaleEnabled) || !$hasInternetConnection) { | 
| @@ -71,7 +71,7 @@ discard block | ||
| 71 | 71 | } | 
| 72 | 72 | |
| 73 | 73 |  		$lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); | 
| 74 | -		if(empty($lookupServerUrl)) { | |
| 74 | +		if (empty($lookupServerUrl)) { | |
| 75 | 75 | return false; | 
| 76 | 76 | } | 
| 77 | 77 | $lookupServerUrl = rtrim($lookupServerUrl, '/'); | 
| @@ -80,7 +80,7 @@ discard block | ||
| 80 | 80 |  		try { | 
| 81 | 81 | $client = $this->clientService->newClient(); | 
| 82 | 82 | $response = $client->get( | 
| 83 | - $lookupServerUrl . '/users?search=' . urlencode($search), | |
| 83 | + $lookupServerUrl.'/users?search='.urlencode($search), | |
| 84 | 84 | [ | 
| 85 | 85 | 'timeout' => 10, | 
| 86 | 86 | 'connect_timeout' => 3, | 
| @@ -93,7 +93,7 @@ discard block | ||
| 93 | 93 |  				try { | 
| 94 | 94 | $remote = $this->cloudIdManager->resolveCloudId($lookup['federationId'])->getRemote(); | 
| 95 | 95 |  				} catch (\Exception $e) { | 
| 96 | -					$this->logger->error('Can not parse federated cloud ID "' .  $lookup['federationId'] . '"'); | |
| 96 | +					$this->logger->error('Can not parse federated cloud ID "'.$lookup['federationId'].'"'); | |
| 97 | 97 | $this->logger->error($e->getMessage()); | 
| 98 | 98 | continue; | 
| 99 | 99 | } | 
| @@ -101,7 +101,7 @@ discard block | ||
| 101 | 101 | continue; | 
| 102 | 102 | } | 
| 103 | 103 | $name = isset($lookup['name']['value']) ? $lookup['name']['value'] : ''; | 
| 104 | -				$label = empty($name) ? $lookup['federationId'] : $name . ' (' . $lookup['federationId'] . ')'; | |
| 104 | +				$label = empty($name) ? $lookup['federationId'] : $name.' ('.$lookup['federationId'].')'; | |
| 105 | 105 | $result[] = [ | 
| 106 | 106 | 'label' => $label, | 
| 107 | 107 | 'value' => [ |