Skip to content

Commit

Permalink
check right location to verify web page and query lookup server for e…
Browse files Browse the repository at this point in the history
…xact cloud id to check if the email address was verified correctly

Signed-off-by: Bjoern Schiessle <[email protected]>
  • Loading branch information
schiessle committed Apr 21, 2017
1 parent a88fbba commit 69d179f
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions settings/BackgroundJobs/VerifyUserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OC\BackgroundJob\Job;
use OC\BackgroundJob\JobList;
use OCP\AppFramework\Http;
use OCP\BackgroundJob\IJobList;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\ILogger;
Expand Down Expand Up @@ -135,7 +136,7 @@ protected function verifyWebsite(array $argument) {

$result = false;

$url = rtrim($argument['data'], '/') . '/' . 'CloudIdVerificationCode.txt';
$url = rtrim($argument['data'], '/') . '/well-known/' . 'CloudIdVerificationCode.txt';

$client = $this->httpClientService->newClient();
try {
Expand All @@ -147,6 +148,8 @@ protected function verifyWebsite(array $argument) {
if ($response->getStatusCode() === Http::STATUS_OK) {
$result = true;
$publishedCode = $response->getBody();
// remove new lines and spaces
$publishedCodeSanitized = $string = trim(preg_replace('/\s\s+/', ' ', $publishedCode));
$user = $this->userManager->get($argument['uid']);
// we don't check a valid user -> give up
if ($user === null) {
Expand All @@ -155,11 +158,10 @@ protected function verifyWebsite(array $argument) {
}
$userData = $this->accountManager->getUser($user);

if ($publishedCode === $argument['verificationCode']) {

$userData[AccountManager::PROPERTY_WEBSITE]['verified'] === AccountManager::VERIFIED;
if ($publishedCodeSanitized === $argument['verificationCode']) {
$userData[AccountManager::PROPERTY_WEBSITE]['verified'] = AccountManager::VERIFIED;
} else {
$userData[AccountManager::PROPERTY_WEBSITE]['verified'] === AccountManager::NOT_VERIFIED;
$userData[AccountManager::PROPERTY_WEBSITE]['verified'] = AccountManager::NOT_VERIFIED;
}

$this->accountManager->updateUser($user, $userData);
Expand Down Expand Up @@ -202,11 +204,11 @@ protected function verifyViaLookupServer(array $argument, $dataType) {
}

// lookup server hasn't verified the email address so far, try again later
if ($lookupServerData[$dataType]['verified'] === AccountManager::VERIFICATION_IN_PROGRESS) {
if ($lookupServerData[$dataType]['verified'] === AccountManager::NOT_VERIFIED) {
return false;
}

$localUserData[$dataType]['verified'] === $lookupServerData[$dataType]['verified'];
$localUserData[$dataType]['verified'] = AccountManager::VERIFIED;
$this->accountManager->updateUser($user, $localUserData);

return true;
Expand All @@ -218,9 +220,9 @@ protected function verifyViaLookupServer(array $argument, $dataType) {
*/
protected function queryLookupServer($cloudId) {
try {
$client = $this->clientService->newClient();
$client = $this->httpClientService->newClient();
$response = $client->get(
$this->lookupServerUrl . '/users?search=' . urlencode($cloudId),
$this->lookupServerUrl . '/users?search=' . urlencode($cloudId) . '&exactCloudId=1',
[
'timeout' => 10,
'connect_timeout' => 3,
Expand All @@ -229,10 +231,8 @@ protected function queryLookupServer($cloudId) {

$body = json_decode($response->getBody(), true);

foreach ($body as $lookup) {
if ($lookup['federationId'] === $cloudId) {
return $lookup;
}
if ($body['federationId'] === $cloudId) {
return $body;
}

} catch (\Exception $e) {
Expand Down

0 comments on commit 69d179f

Please sign in to comment.