]> source.dussan.org Git - nextcloud-server.git/commitdiff
Extract updateSharePasswordIfNeeded function
authorDaniel Calviño Sánchez <danxuliu@gmail.com>
Sun, 23 Apr 2017 17:47:28 +0000 (19:47 +0200)
committerDaniel Calviño Sánchez <danxuliu@gmail.com>
Mon, 24 Apr 2017 11:38:36 +0000 (13:38 +0200)
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
lib/private/Share20/Manager.php

index 3e4d5cc3813ae53226f9f95f7f4f2ba9aa2d4085..1407d89d1124f83d6f6c7009fa5df6abc758f693 100644 (file)
@@ -715,16 +715,7 @@ class Manager implements IManager {
                } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
                        $this->linkCreateChecks($share);
 
-                       // Password updated.
-                       if ($share->getPassword() !== $originalShare->getPassword()) {
-                               //Verify the password
-                               $this->verifyPassword($share->getPassword());
-
-                               // If a password is set. Hash it!
-                               if ($share->getPassword() !== null) {
-                                       $share->setPassword($this->hasher->hash($share->getPassword()));
-                               }
-                       }
+                       $this->updateSharePasswordIfNeeded($share, $originalShare);
 
                        if ($share->getExpirationDate() != $originalShare->getExpirationDate()) {
                                //Verify the expiration date
@@ -732,18 +723,9 @@ class Manager implements IManager {
                                $expirationDateUpdated = true;
                        }
                } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
-                       $plainTextPassword = null;
-
-                       // Password updated.
-                       if ($share->getPassword() !== $originalShare->getPassword()) {
-                               //Verify the password
-                               $this->verifyPassword($share->getPassword());
-
-                               // If a password is set. Hash it!
-                               if ($share->getPassword() !== null) {
-                                       $plainTextPassword = $share->getPassword();
-                                       $share->setPassword($this->hasher->hash($plainTextPassword));
-                               }
+                       $plainTextPassword = $share->getPassword();
+                       if (!$this->updateSharePasswordIfNeeded($share, $originalShare)) {
+                               $plainTextPassword = null;
                        }
                }
 
@@ -796,6 +778,32 @@ class Manager implements IManager {
                return $share;
        }
 
+       /**
+        * Updates the password of the given share if it is not the same as the
+        * password of the original share.
+        *
+        * @param \OCP\Share\IShare $share the share to update its password.
+        * @param \OCP\Share\IShare $originalShare the original share to compare its
+        *        password with.
+        * @return boolean whether the password was updated or not.
+        */
+       private function updateSharePasswordIfNeeded(\OCP\Share\IShare $share, \OCP\Share\IShare $originalShare) {
+               // Password updated.
+               if ($share->getPassword() !== $originalShare->getPassword()) {
+                       //Verify the password
+                       $this->verifyPassword($share->getPassword());
+
+                       // If a password is set. Hash it!
+                       if ($share->getPassword() !== null) {
+                               $share->setPassword($this->hasher->hash($share->getPassword()));
+
+                               return true;
+                       }
+               }
+
+               return false;
+       }
+
        /**
         * Delete all the children of this share
         * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in