<?php
namespace Elements\Bundle\AzureAuthBundle\EventSubscriber;
use Pimcore\Model\User;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Pimcore\Event\Model\UserRoleEvent;
class PasswordChangeSubscriber implements EventSubscriberInterface
{
/**
* @return array[]
*/
public static function getSubscribedEvents()
{
return [
'pimcore.user.preUpdate' => [
['onPasswordChange', 10]
],
];
}
/**
* @param UserRoleEvent $event
* @return void
*/
public function onPasswordChange(UserRoleEvent $event)
{
$user = $event->getUserRole();
if($user instanceof User){
$folder = User\Folder::getById($user->getParentId());
if($folder instanceof User\Folder){
if($folder->getName() == 'elements.at' || $folder->getName() == 'valantic.at'){
$user->setPassword(microtime(true) . uniqid());
}
}
}
}
}