Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VerifyUserData shall use IAccountManager, not private API #26959

Merged
merged 1 commit into from
May 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 29 additions & 30 deletions apps/settings/lib/BackgroundJobs/VerifyUserData.php
Original file line number Diff line number Diff line change
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;
}
}
}
}