diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2022-05-05 20:19:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-05 20:19:28 +0200 |
commit | 0284c0f71797cf2729633f18c5905c23457cd527 (patch) | |
tree | 28131ca9a83c2afe81d5fc57c161a25d9387ec1a | |
parent | 99151a55890727253339f49406e2ceba56db47e4 (diff) | |
parent | 8a2cf5bb68617004d24469c65b68e8b01ca56621 (diff) | |
download | nextcloud-server-0284c0f71797cf2729633f18c5905c23457cd527.tar.gz nextcloud-server-0284c0f71797cf2729633f18c5905c23457cd527.zip |
Merge pull request #32276 from nextcloud/fix/ldap_error_handling
Do not dispatch postSetPassword when setPassword fails
-rw-r--r-- | apps/settings/lib/Controller/ChangePasswordController.php | 5 | ||||
-rw-r--r-- | lib/private/User/User.php | 16 | ||||
-rw-r--r-- | tests/Core/Controller/ChangePasswordControllerTest.php | 6 |
3 files changed, 20 insertions, 7 deletions
diff --git a/apps/settings/lib/Controller/ChangePasswordController.php b/apps/settings/lib/Controller/ChangePasswordController.php index 8dd1e6ba028..85e4218ebb5 100644 --- a/apps/settings/lib/Controller/ChangePasswordController.php +++ b/apps/settings/lib/Controller/ChangePasswordController.php @@ -109,7 +109,10 @@ class ChangePasswordController extends Controller { try { if ($newpassword === null || $user->setPassword($newpassword) === false) { return new JSONResponse([ - 'status' => 'error' + 'status' => 'error', + 'data' => [ + 'message' => $this->l->t('Unable to change personal password'), + ], ]); } // password policy app throws exception diff --git a/lib/private/User/User.php b/lib/private/User/User.php index 0a51622428b..e7aa72fafba 100644 --- a/lib/private/User/User.php +++ b/lib/private/User/User.php @@ -320,13 +320,17 @@ class User implements IUser { } if ($this->backend->implementsActions(Backend::SET_PASSWORD)) { $result = $this->backend->setPassword($this->uid, $password); - $this->legacyDispatcher->dispatch(IUser::class . '::postSetPassword', new GenericEvent($this, [ - 'password' => $password, - 'recoveryPassword' => $recoveryPassword, - ])); - if ($this->emitter) { - $this->emitter->emit('\OC\User', 'postSetPassword', [$this, $password, $recoveryPassword]); + + if ($result !== false) { + $this->legacyDispatcher->dispatch(IUser::class . '::postSetPassword', new GenericEvent($this, [ + 'password' => $password, + 'recoveryPassword' => $recoveryPassword, + ])); + if ($this->emitter) { + $this->emitter->emit('\OC\User', 'postSetPassword', [$this, $password, $recoveryPassword]); + } } + return !($result === false); } else { return false; diff --git a/tests/Core/Controller/ChangePasswordControllerTest.php b/tests/Core/Controller/ChangePasswordControllerTest.php index 190afd3be47..2d7292f6801 100644 --- a/tests/Core/Controller/ChangePasswordControllerTest.php +++ b/tests/Core/Controller/ChangePasswordControllerTest.php @@ -138,6 +138,9 @@ class ChangePasswordControllerTest extends \Test\TestCase { $expects = [ 'status' => 'error', + 'data' => [ + 'message' => 'Unable to change personal password', + ], ]; $res = $this->controller->changePersonalPassword('old'); @@ -163,6 +166,9 @@ class ChangePasswordControllerTest extends \Test\TestCase { $expects = new JSONResponse([ 'status' => 'error', + 'data' => [ + 'message' => 'Unable to change personal password', + ], ]); $actual = $this->controller->changePersonalPassword('old', 'new'); |