All checks were successful
Auto Tag Develop / tag (push) Successful in 5s
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | 315 | Création d'une page d'administration : modification/création d'un utilisateur | ## Description de la PR ## Modification du .env ## Check list - [x] Pas de régression - [ ] TU/TI/TF rédigée - [x] TU/TI/TF OK - [x] CHANGELOG modifié Reviewed-on: #17 Reviewed-by: Autin <tristan@yuno.malio.fr> Co-authored-by: kevin <kevin@yuno.malio.fr> Co-committed-by: kevin <kevin@yuno.malio.fr>
41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\State;
|
|
|
|
use ApiPlatform\Metadata\Operation;
|
|
use ApiPlatform\State\ProcessorInterface;
|
|
use App\Entity\User;
|
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
|
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
|
|
|
final class UserPasswordProcessor implements ProcessorInterface
|
|
{
|
|
public function __construct(
|
|
private readonly UserPasswordHasherInterface $hasher,
|
|
#[Autowire(service: 'api_platform.doctrine.orm.state.persist_processor')]
|
|
private readonly ProcessorInterface $persistProcessor
|
|
) {}
|
|
|
|
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): mixed
|
|
{
|
|
if ($data instanceof User) {
|
|
$plain = $data->getPassword();
|
|
if ('' !== $plain) {
|
|
$data->setPassword($this->hasher->hashPassword(
|
|
$data,
|
|
$plain
|
|
));
|
|
}
|
|
}
|
|
|
|
return $this->persistProcessor->process(
|
|
$data,
|
|
$operation,
|
|
$uriVariables,
|
|
$context
|
|
);
|
|
}
|
|
}
|