aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/lib/BackgroundJobs
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2021-05-12 12:17:07 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2021-05-12 22:57:20 +0200
commit99770273217f63840d76c04545bd758eb63690ba (patch)
treed85c8cf75b78e9189c872d3aa9e35c066b8f67bc /apps/settings/lib/BackgroundJobs
parent9b36252de0f7cc6b971c8a23524495e38f35dcf2 (diff)
downloadnextcloud-server-99770273217f63840d76c04545bd758eb63690ba.tar.gz
nextcloud-server-99770273217f63840d76c04545bd758eb63690ba.zip
VerifyUserData shall use IAccountManager, not private API
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/settings/lib/BackgroundJobs')
-rw-r--r--apps/settings/lib/BackgroundJobs/VerifyUserData.php59
1 files changed, 29 insertions, 30 deletions
diff --git a/apps/settings/lib/BackgroundJobs/VerifyUserData.php b/apps/settings/lib/BackgroundJobs/VerifyUserData.php
index 9e99f3a0ad7..ee1cc43c53b 100644
--- a/apps/settings/lib/BackgroundJobs/VerifyUserData.php
+++ b/apps/settings/lib/BackgroundJobs/VerifyUserData.php
@@ -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;
+ }
}
}
}