<?php
/**
* Pimcore
*
* This source file is available under following license:
* - Pimcore Commercial License (PCL)
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license PCL
*/
namespace Pimcore\Bundle\PortalEngineBundle\Service\Security\Authentication\User;
use Pimcore\Bundle\PortalEngineBundle\Enum\Permission;
use Pimcore\Bundle\PortalEngineBundle\Event\Auth\LoginPasswordChangeableEvent;
use Pimcore\Bundle\PortalEngineBundle\Service\Security\PermissionService;
use Pimcore\Bundle\PortalEngineBundle\Service\Security\SecurityService;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Class PasswordChangeableService
*
* @package Pimcore\Bundle\PortalEngineBundle\Service\Security\Authentication\User
*/
class PasswordChangeableService
{
/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;
/**
* @var SecurityService
*/
private $securityService;
/**
* @var PermissionService
*/
private $permissionService;
public function __construct(EventDispatcherInterface $eventDispatcher, SecurityService $securityService, PermissionService $permissionService)
{
$this->eventDispatcher = $eventDispatcher;
$this->securityService = $securityService;
$this->permissionService = $permissionService;
}
public function isPasswordChangeable(): bool
{
$event = new LoginPasswordChangeableEvent();
if ($portalUser = $this->securityService->getPortalUser()) {
$event->setPasswordChangeable($this->permissionService->isAllowed($portalUser, Permission::PASSWORD_CHANGE));
}
$this->eventDispatcher->dispatch($event);
return $event->getPasswordChangeable();
}
}