vendor/pimcore/portal-engine/src/Service/Security/Authentication/User/PasswordChangeableService.php line 50

  1. * Pimcore Open Core License (POCL)
  2. * Full copyright and license information is available in
  3. * LICENSE.md which is distributed with this source code.
  4. *
  5. * @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
  6. * @license Pimcore Open Core License (POCL)
  7. */
  8. namespace Pimcore\Bundle\PortalEngineBundle\Service\Security\Authentication\User;
  9. use Pimcore\Bundle\PortalEngineBundle\Enum\Permission;
  10. use Pimcore\Bundle\PortalEngineBundle\Event\Auth\LoginPasswordChangeableEvent;
  11. use Pimcore\Bundle\PortalEngineBundle\Service\Security\PermissionService;
  12. use Pimcore\Bundle\PortalEngineBundle\Service\Security\SecurityService;
  13. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  14. /**
  15. * @internal
  16. */
  17. class PasswordChangeableService
  18. {
  19. public function __construct(
  20. private readonly EventDispatcherInterface $eventDispatcher,
  21. private readonly SecurityService $securityService,
  22. private readonly PermissionService $permissionService
  23. ) {
  24. }
  25. public function isPasswordChangeable(): bool
  26. {
  27. $event = new LoginPasswordChangeableEvent();
  28. if ($portalUser = $this->securityService->getPortalUser()) {
  29. $event->setPasswordChangeable($this->permissionService->isAllowed($portalUser, Permission::PASSWORD_CHANGE));
  30. }
  31. $this->eventDispatcher->dispatch($event);
  32. return $event->getPasswordChangeable();
  33. }
  34. }