Skip to content

Commit

Permalink
Merge pull request #26959 from nextcloud/techdebt/noid/verifiyuserdat…
Browse files Browse the repository at this point in the history
…a-iaccountmanager

VerifyUserData shall use IAccountManager, not private API
  • Loading branch information
blizzz committed May 12, 2021
2 parents a923213 + 9977027 commit b8b2e79
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions apps/settings/lib/BackgroundJobs/VerifyUserData.php
Expand Up @@ -30,8 +30,8 @@

namespace OCA\Settings\BackgroundJobs;

use OC\Accounts\AccountManager;
use OCP\Accounts\IAccountManager;
use OCP\Accounts\PropertyDoesNotExistException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
Expand All @@ -52,7 +52,7 @@ class VerifyUserData extends Job {
/** @var int how much time should be between two tries (1 hour) */
private $interval = 3600;

/** @var AccountManager */
/** @var IAccountManager */
private $accountManager;

/** @var IUserManager */
Expand All @@ -70,7 +70,7 @@ class VerifyUserData extends Job {
/** @var IConfig */
private $config;

public function __construct(AccountManager $accountManager,
public function __construct(IAccountManager $accountManager,
IUserManager $userManager,
IClientService $clientService,
ILogger $logger,
Expand Down Expand Up @@ -157,28 +157,19 @@ protected function verifyWebsite(array $argument) {
$this->logger->error($argument['uid'] . ' doesn\'t exist, can\'t verify user data.');
return $result;
}
$userData = $this->accountManager->getUser($user);

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

$this->accountManager->updateUser($user, $userData);
$userAccount = $this->accountManager->getAccount($user);
$websiteProp = $userAccount->getProperty(IAccountManager::PROPERTY_WEBSITE);
$websiteProp->setVerified($publishedCodeSanitized === $argument['verificationCode']
? IAccountManager::VERIFIED
: IAccountManager::NOT_VERIFIED
);
$this->accountManager->updateAccount($userAccount);
}

return $result;
}

/**
* verify email address
*
* @param array $argument
* @param string $dataType
* @return bool true if we could check the verification code, otherwise false
*/
protected function verifyViaLookupServer(array $argument, $dataType) {
protected function verifyViaLookupServer(array $argument, string $dataType): bool {
if (empty($this->lookupServerUrl) ||
$this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes') !== 'yes' ||
$this->config->getSystemValue('has_internet_connection', true) === false) {
Expand All @@ -193,10 +184,7 @@ protected function verifyViaLookupServer(array $argument, $dataType) {
return true;
}

$localUserData = $this->accountManager->getUser($user);
$cloudId = $user->getCloudId();

// ask lookup-server for user data
$lookupServerData = $this->queryLookupServer($cloudId);

// for some reasons we couldn't read any data from the lookup server, try again later
Expand All @@ -210,12 +198,18 @@ protected function verifyViaLookupServer(array $argument, $dataType) {
}

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

$localUserData[$dataType]['verified'] = AccountManager::VERIFIED;
$this->accountManager->updateUser($user, $localUserData);
try {
$userAccount = $this->accountManager->getAccount($user);
$property = $userAccount->getProperty($dataType);
$property->setVerified(IAccountManager::VERIFIED);
$this->accountManager->updateAccount($userAccount);
} catch (PropertyDoesNotExistException $e) {
return false;
}

return true;
}
Expand Down Expand Up @@ -281,12 +275,17 @@ protected function shouldRun(array $argument) {
/**
* reset verification state after max tries are reached
*/
protected function resetVerificationState() {
protected function resetVerificationState(): void {
$user = $this->userManager->get($this->argument['uid']);
if ($user !== null) {
$accountData = $this->accountManager->getUser($user);
$accountData[$this->argument['type']]['verified'] = AccountManager::NOT_VERIFIED;
$this->accountManager->updateUser($user, $accountData);
$userAccount = $this->accountManager->getAccount($user);
try {
$property = $userAccount->getProperty($this->argument['type']);
$property->setVerified(IAccountManager::NOT_VERIFIED);
$this->accountManager->updateAccount($userAccount);
} catch (PropertyDoesNotExistException $e) {
return;
}
}
}
}

0 comments on commit b8b2e79

Please sign in to comment.