VerifyUserData shall use IAccountManager, not private API

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2021-05-12 12:17:07 +02:00
parent 9b36252de0
commit 9977027321
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
1 changed files with 29 additions and 30 deletions

View File

@ -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;
@ -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 */
@ -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,
@ -157,28 +157,19 @@ class VerifyUserData extends Job {
$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) {
@ -193,10 +184,7 @@ class VerifyUserData extends Job {
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
@ -210,12 +198,18 @@ class VerifyUserData extends Job {
}
// 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;
}
@ -281,12 +275,17 @@ class VerifyUserData extends Job {
/**
* 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;
}
}
}
}