summaryrefslogtreecommitdiffstats
path: root/lib/private/Share20
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2017-04-23 19:47:28 +0200
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2017-04-24 13:38:36 +0200
commitfaea890b874857f2ff144c7eb26dec58a3661005 (patch)
treef1e7316dad1f57c62b978c71a8fb336033e4873e /lib/private/Share20
parent51e658da2aeab432858146ad5f8f09d8e2d6c850 (diff)
downloadnextcloud-server-faea890b874857f2ff144c7eb26dec58a3661005.tar.gz
nextcloud-server-faea890b874857f2ff144c7eb26dec58a3661005.zip
Extract updateSharePasswordIfNeeded function
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'lib/private/Share20')
-rw-r--r--lib/private/Share20/Manager.php52
1 files changed, 30 insertions, 22 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index 3e4d5cc3813..1407d89d112 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -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;
}
}
@@ -797,6 +779,32 @@ class Manager implements IManager {
}
/**
+ * 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
*