]> source.dussan.org Git - nextcloud-server.git/commitdiff
adjust email verification checker
authorArthur Schiwon <blizzz@arthur-schiwon.de>
Tue, 22 Jun 2021 11:41:48 +0000 (13:41 +0200)
committerArthur Schiwon <blizzz@arthur-schiwon.de>
Tue, 29 Jun 2021 22:47:36 +0000 (00:47 +0200)
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
lib/private/Accounts/AccountManager.php
tests/lib/Accounts/AccountManagerTest.php

index 20f596e3a90f599f24bb6e138db9aff8e2c21625..651663a57cc23c4e29fa61b2433ae34db3938920 100644 (file)
@@ -228,7 +228,7 @@ class AccountManager implements IAccountManager {
                $updated = true;
 
                if ($userData !== $data) {
-                       $data = $this->checkEmailVerification($userData, $data, $user);
+
                        $this->updateExistingUser($user, $data);
                } else {
                        // nothing needs to be done if new and old data set are the same
@@ -340,30 +340,31 @@ class AccountManager implements IAccountManager {
 
        /**
         * check if we need to ask the server for email verification, if yes we create a cronjob
-        *
-        * @param $oldData
-        * @param $newData
-        * @param IUser $user
-        * @return array
-        */
-       protected function checkEmailVerification($oldData, $newData, IUser $user): array {
-               if ($oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']) {
 
+        */
+       protected function checkEmailVerification(IAccount $updatedAccount, array $oldData): void {
+               try {
+                       $property = $updatedAccount->getProperty(self::PROPERTY_EMAIL);
+               } catch (PropertyDoesNotExistException $e) {
+                       return;
+               }
+               if ($oldData[self::PROPERTY_EMAIL]['value'] !== $property->getValue()) {
                        $this->jobList->add(VerifyUserData::class,
                                [
                                        'verificationCode' => '',
-                                       'data' => $newData[self::PROPERTY_EMAIL]['value'],
+                                       'data' => $property->getValue(),
                                        'type' => self::PROPERTY_EMAIL,
-                                       'uid' => $user->getUID(),
+                                       'uid' => $updatedAccount->getUser()->getUID(),
                                        'try' => 0,
                                        'lastRun' => time()
                                ]
                        );
-                       $newData[self::PROPERTY_EMAIL]['verified'] = self::VERIFICATION_IN_PROGRESS;
 
-               }
 
-               return $newData;
+
+
+                       $property->setVerified(self::VERIFICATION_IN_PROGRESS);
+               }
        }
 
        /**
@@ -639,8 +640,9 @@ class AccountManager implements IAccountManager {
                        $this->testPropertyScope($property, $allowedScopes, true);
                }
 
-               $this->updateVerificationStatus($account, $this->getUser($account->getUser(), false));
-
+               $oldData = $this->getUser($account->getUser(), false);
+               $this->updateVerificationStatus($account, $oldData);
+               $this->checkEmailVerification($account, $oldData);
 
                $this->updateUser($account->getUser(), $data, true);
        }
index d70d453c24883d94d40d9e6ad53e94ebe0d4b0b3..3448c471cd757aa5b323ceabe3ea4f0d566e8318 100644 (file)
@@ -278,7 +278,7 @@ class AccountManagerTest extends TestCase {
         * @param bool $updateExisting
         */
        public function testUpdateUser($newData, $oldData, $insertNew, $updateExisting) {
-               $accountManager = $this->getInstance(['getUser', 'insertNewUser', 'updateExistingUser', 'checkEmailVerification']);
+               $accountManager = $this->getInstance(['getUser', 'insertNewUser', 'updateExistingUser']);
                /** @var IUser $user */
                $user = $this->createMock(IUser::class);
 
@@ -286,8 +286,6 @@ class AccountManagerTest extends TestCase {
                $accountManager->expects($this->once())->method('getUser')->with($user)->willReturn($oldData);
 
                if ($updateExisting) {
-                       $accountManager->expects($this->once())->method('checkEmailVerification')
-                               ->with($oldData, $newData, $user)->willReturn($newData);
                        $accountManager->expects($this->once())->method('updateExistingUser')
                                ->with($user, $newData);
                        $accountManager->expects($this->never())->method('insertNewUser');
@@ -300,7 +298,6 @@ class AccountManagerTest extends TestCase {
 
                if (!$insertNew && !$updateExisting) {
                        $accountManager->expects($this->never())->method('updateExistingUser');
-                       $accountManager->expects($this->never())->method('checkEmailVerification');
                        $accountManager->expects($this->never())->method('insertNewUser');
                        $this->eventDispatcher->expects($this->never())->method('dispatch');
                } else {