mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-04 04:19:43 +00:00
Fix fixtures
- Inject parameters directly instead of getting from container - User PasswordHasher instead of EncoderFactory - set parameters directly and correctly encode values to json
This commit is contained in:
@@ -19,7 +19,7 @@ use Chill\MainBundle\Entity\User;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Symfony\Component\Security\Core\Encoder\EncoderFactory;
|
||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||
|
||||
/**
|
||||
* Load fixtures users into database.
|
||||
@@ -53,6 +53,14 @@ class LoadUsers extends Fixture implements OrderedFixtureInterface
|
||||
'centerB_permission_group_social', ],
|
||||
],
|
||||
];
|
||||
|
||||
private UserPasswordHasherInterface $passwordHasher;
|
||||
|
||||
public function __construct(UserPasswordHasherInterface $passwordHasher)
|
||||
{
|
||||
$this->passwordHasher = $passwordHasher;
|
||||
}
|
||||
|
||||
public function getOrder(): int
|
||||
{
|
||||
return 1000;
|
||||
@@ -74,17 +82,11 @@ class LoadUsers extends Fixture implements OrderedFixtureInterface
|
||||
|
||||
$defaultEncoder = new \Symfony\Component\PasswordHasher\Hasher\MessageDigestPasswordHasher('sha512', true, 5000);
|
||||
|
||||
$encoderFactory = new EncoderFactory([
|
||||
User::class => $defaultEncoder,
|
||||
]);
|
||||
$hashedPassword = $this->passwordHasher->hashPassword($user, 'password');
|
||||
|
||||
$user
|
||||
->setUsername($username)
|
||||
->setPassword(
|
||||
$encoderFactory
|
||||
->getEncoder($user)
|
||||
->encodePassword('password', $user->getSalt())
|
||||
)
|
||||
->setPassword($hashedPassword)
|
||||
->setEmail(sprintf('%s@chill.social', \str_replace(' ', '', (string) $username)));
|
||||
|
||||
foreach ($params['groupCenterRefs'] as $groupCenterRef) {
|
||||
|
Reference in New Issue
Block a user