diff options
author | Louis Chemineau <louis@chmn.me> | 2022-04-19 15:56:56 +0200 |
---|---|---|
committer | backportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com> | 2022-06-22 10:27:37 +0000 |
commit | e6a254641e664a75616c5a13d1de80c1fcc3cf02 (patch) | |
tree | b250d6c56fb664b144573fa98db644281e57e8a4 /apps/files_external/lib | |
parent | c530f8a77c772a484a4bfafd352cc00a03b15949 (diff) | |
download | nextcloud-server-e6a254641e664a75616c5a13d1de80c1fcc3cf02.tar.gz nextcloud-server-e6a254641e664a75616c5a13d1de80c1fcc3cf02.zip |
Use stored user for PasswordUpdatedEvent
When handling PasswordUpdatedEvent event, we are calling getLoginName which does not exists.
This PR adds a condition to use the previously stored user when handling PasswordUpdatedEvent.
Signed-off-by: Louis Chemineau <louis@chmn.me>
Diffstat (limited to 'apps/files_external/lib')
-rw-r--r-- | apps/files_external/lib/Listener/StorePasswordListener.php | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/apps/files_external/lib/Listener/StorePasswordListener.php b/apps/files_external/lib/Listener/StorePasswordListener.php index bd0c4dc1ffd..66232a78a93 100644 --- a/apps/files_external/lib/Listener/StorePasswordListener.php +++ b/apps/files_external/lib/Listener/StorePasswordListener.php @@ -50,19 +50,27 @@ class StorePasswordListener implements IEventListener { return; } - $stored = $this->credentialsManager->retrieve($event->getUser()->getUID(), LoginCredentials::CREDENTIALS_IDENTIFIER); - $update = isset($stored['password']) && $stored['password'] !== $event->getPassword(); - if (!$update && $event instanceof UserLoggedInEvent) { - $update = isset($stored['user']) && $stored['user'] !== $event->getLoginName(); + $storedCredentials = $this->credentialsManager->retrieve($event->getUser()->getUID(), LoginCredentials::CREDENTIALS_IDENTIFIER); + + if (!$storedCredentials) { + return; + } + + $newCredentials = $storedCredentials; + $shouldUpdate = false; + + if (isset($storedCredentials['password']) && $storedCredentials['password'] !== $event->getPassword()) { + $shouldUpdate = true; + $newCredentials['password'] = $event->getPassword(); } - if ($stored && $update) { - $credentials = [ - 'user' => $event->getLoginName(), - 'password' => $event->getPassword() - ]; + if (isset($storedCredentials['user']) && $event instanceof UserLoggedInEvent && $storedCredentials['user'] !== $event->getLoginName()) { + $shouldUpdate = true; + $newCredentials['user'] = $event->getLoginName(); + } - $this->credentialsManager->store($event->getUser()->getUID(), LoginCredentials::CREDENTIALS_IDENTIFIER, $credentials); + if ($shouldUpdate) { + $this->credentialsManager->store($event->getUser()->getUID(), LoginCredentials::CREDENTIALS_IDENTIFIER, $newCredentials); } } } |