]> source.dussan.org Git - nextcloud-server.git/commitdiff
Use stored user for PasswordUpdatedEvent 32016/head
authorLouis Chemineau <louis@chmn.me>
Tue, 19 Apr 2022 13:56:56 +0000 (15:56 +0200)
committerLouis Chemineau <louis@chmn.me>
Tue, 10 May 2022 10:16:33 +0000 (12:16 +0200)
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>
apps/files_external/lib/Listener/StorePasswordListener.php

index bd0c4dc1ffd7f544c3798815f7630983c20ef08c..66232a78a9301a5671fcaebff2928efecdc0e4b8 100644 (file)
@@ -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);
                }
        }
 }