Skip to content

Commit

Permalink
Use stored user for PasswordUpdatedEvent
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
artonge committed May 5, 2022
1 parent 290697b commit 2b9d29f
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions apps/files_external/lib/Listener/StorePasswordListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,27 @@ public function handle(Event $event): void {
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);
}
}
}

0 comments on commit 2b9d29f

Please sign in to comment.