diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2022-07-05 13:32:37 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-05 13:32:37 +0300 |
commit | 1c83b2bc50748d8519e5a8943ef4d0e0e94b83cf (patch) | |
tree | 03d85b5e5b9e43f3cb73a2df37c6838ae8f02a2e | |
parent | 6c76080c3a46ebb65afe5e55f0be7ac4ced6aae7 (diff) | |
parent | 673cef97c02e2601000064026e273526c59eb25f (diff) |
Merge pull request #32976 from nextcloud/backport/32016/stable22
[stable22] Use stored user for PasswordUpdatedEvent
-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); } } } |