Skip to content

Commit

Permalink
Merge pull request #32974 from nextcloud/backport/32016/stable24
Browse files Browse the repository at this point in the history
[stable24] Use stored user for PasswordUpdatedEvent
  • Loading branch information
blizzz authored Jul 5, 2022
2 parents a22ecac + e6a2546 commit 51afde1
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 51afde1

Please sign in to comment.