Skip to content

Commit

Permalink
Keep cache of passwords changed during request so we won't trigger twice
Browse files Browse the repository at this point in the history
  • Loading branch information
lsimeonov committed Aug 6, 2018
1 parent 19eaee8 commit 4013406
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/EventListener/PasswordEntityListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class PasswordEntityListener
*/
private $processedNewEntities = [];

/**
* @var array
*/
private $processedPasswords =[];

/**
* PasswordEntityListener constructor.
* @param \Despark\PasswordPolicyBundle\Service\PasswordHistoryServiceInterface $passwordHistoryService
Expand Down Expand Up @@ -118,6 +123,10 @@ public function createPasswordHistory(
return null;
}

if(array_key_exists($oldPassword, $this->processedPasswords)){
return null;
}

$uow = $em->getUnitOfWork();
$entityMeta = $em->getClassMetadata(get_class($entity));

Expand Down Expand Up @@ -145,6 +154,7 @@ public function createPasswordHistory(

$entity->addPasswordHistory($history);

$this->processedPasswords[$oldPassword] = $history;

$stalePasswords = $this->passwordHistoryService->getHistoryItemsForCleanup($entity, $this->historyLimit);

Expand Down

0 comments on commit 4013406

Please sign in to comment.