Skip to content

Commit

Permalink
fix create user
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinDev committed Mar 22, 2021
1 parent b121720 commit e52681e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/core/src/EventListener/UserListener.php
Expand Up @@ -2,7 +2,9 @@

namespace Pushword\Core\EventListener;

use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Doctrine\ORM\Mapping\PreUpdate;
use Pushword\Core\Entity\UserInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;

Expand All @@ -18,11 +20,16 @@ public function __construct(UserPasswordEncoderInterface $passwordEncoder)
/**
* Set Password on database update if PlainPassword is set.
*/
public function preUpdate(UserInterface $user, PreUpdateEventArgs $event)
public function preUpdate(UserInterface $user, PreUpdateEventArgs $event = null)
{
if (\strlen($user->getPlainPassword()) > 0) {
$user->setPassword($this->passwordEncoder->encodePassword($user, $user->getPlainPassword()));
$user->eraseCredentials();
}
}

public function prePersist(UserInterface $user, LifecycleEventArgs $event)
{
return $this->preUpdate($user);
}
}
1 change: 1 addition & 0 deletions packages/core/src/Resources/config/CoreServices.yaml
Expand Up @@ -36,6 +36,7 @@ services:
autowire: true
tags:
- { name: doctrine.orm.entity_listener, entity: "%pw.entity_user%", event: preUpdate }
- { name: doctrine.orm.entity_listener, entity: "%pw.entity_user%", event: prePersist }

pushword.page_rendering.validator:
class: Pushword\Core\Validator\Constraints\PageRenderingValidator
Expand Down
Binary file modified packages/skeleton/var/app.db
Binary file not shown.

0 comments on commit e52681e

Please sign in to comment.