removed encoder, set hasher
This commit is contained in:
parent
f7109bbd02
commit
a5e665cbe4
|
@ -29,13 +29,13 @@ class UserCrudController extends AbstractCrudController
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var UserPasswordEncoderInterface
|
* @var UserPasswordHasherInterface
|
||||||
*/
|
*/
|
||||||
private $passwordHasher;
|
private UserPasswordHasherInterface $passwordHasher;
|
||||||
/**
|
/**
|
||||||
* @var Security
|
* @var Security
|
||||||
*/
|
*/
|
||||||
private $security;
|
private Security $security;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UserCrudController constructor.
|
* UserCrudController constructor.
|
||||||
|
@ -61,7 +61,6 @@ class UserCrudController extends AbstractCrudController
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $pageName
|
* @param string $pageName
|
||||||
*
|
*
|
||||||
|
@ -69,7 +68,6 @@ class UserCrudController extends AbstractCrudController
|
||||||
*/
|
*/
|
||||||
public function configureFields(string $pageName): iterable
|
public function configureFields(string $pageName): iterable
|
||||||
{
|
{
|
||||||
//$id = TextField::new('id')->
|
|
||||||
$username = TextField::new('username');
|
$username = TextField::new('username');
|
||||||
$email = TextField::new('email');
|
$email = TextField::new('email');
|
||||||
$firstName = TextField::new('firstName');
|
$firstName = TextField::new('firstName');
|
||||||
|
@ -80,34 +78,31 @@ class UserCrudController extends AbstractCrudController
|
||||||
$roles = ChoiceField::new('roles', 'Roles')
|
$roles = ChoiceField::new('roles', 'Roles')
|
||||||
->allowMultipleChoices()
|
->allowMultipleChoices()
|
||||||
->autocomplete()
|
->autocomplete()
|
||||||
->setChoices([ 'User' => 'ROLE_USER',
|
->setChoices([
|
||||||
'Admin' => 'ROLE_ADMIN',
|
'User' => 'ROLE_USER',
|
||||||
'SuperAdmin' => 'ROLE_SUPER_ADMIN']
|
'Admin' => 'ROLE_ADMIN',
|
||||||
|
'SuperAdmin' => 'ROLE_SUPER_ADMIN']
|
||||||
);
|
);
|
||||||
$password = TextField::new('password')
|
$password = TextField::new('password')
|
||||||
->setFormType(PasswordType::class)
|
->setFormType(PasswordType::class)
|
||||||
->setFormTypeOption('empty_data', '')
|
->setFormTypeOption('empty_data', '')
|
||||||
->setRequired(false)
|
->setRequired(false)
|
||||||
->setHelp('Leave blank to keep the current password');
|
->setHelp('Leave blank to keep the current password');
|
||||||
|
|
||||||
switch ($pageName) {
|
switch ($pageName) {
|
||||||
case Crud::PAGE_INDEX:
|
case Crud::PAGE_INDEX:
|
||||||
return [ $username, $firstName, $lastName, $email, $lastLoginAt ];
|
return [$username, $firstName, $lastName, $email, $lastLoginAt];
|
||||||
break;
|
|
||||||
case Crud::PAGE_DETAIL:
|
case Crud::PAGE_DETAIL:
|
||||||
return [ $username, $firstName, $lastName, $email, $lastLoginAt, $createdAt, $roles, $isVerified ];
|
return [$username, $firstName, $lastName, $email, $lastLoginAt, $createdAt, $roles, $isVerified];
|
||||||
break;
|
|
||||||
case Crud::PAGE_NEW:
|
case Crud::PAGE_NEW:
|
||||||
return [
|
return [
|
||||||
$password,
|
$password,
|
||||||
];
|
];
|
||||||
break;
|
|
||||||
case Crud::PAGE_EDIT:
|
case Crud::PAGE_EDIT:
|
||||||
return [ $username, $password, $firstName, $lastName, $email, $lastLoginAt, $roles, $isVerified ];
|
return [$username, $password, $firstName, $lastName, $email, $lastLoginAt, $roles, $isVerified];
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -117,17 +112,17 @@ class UserCrudController extends AbstractCrudController
|
||||||
*/
|
*/
|
||||||
public function updateEntity(EntityManagerInterface $entityManager, $entityInstance): void
|
public function updateEntity(EntityManagerInterface $entityManager, $entityInstance): void
|
||||||
{
|
{
|
||||||
// set new password with encoder interface
|
// set new password with hash interface
|
||||||
if (method_exists($entityInstance, 'setPassword')) {
|
if (method_exists($entityInstance, 'setPassword')) {
|
||||||
$plainPassword = trim($this->get('request_stack')->getCurrentRequest()->request->all('User')['password']);
|
$plainPassword = trim($this->get('request_stack')->getCurrentRequest()->request->all('User')['password']);
|
||||||
|
|
||||||
// do nothing if no password is entered
|
// do nothing if no password is entered
|
||||||
if (isset($plainPassword) === true && $plainPassword === '') {
|
if (isset($plainPassword) === true && $plainPassword === '') {
|
||||||
$entityInstance->setPassword($this->password);
|
$entityInstance->setPassword($this->password);
|
||||||
} else {
|
} else {
|
||||||
$user = new User();
|
$user = new User();
|
||||||
$encodedPassword = $this->passwordHasher->hashPassword($user, $plainPassword);
|
$hashedPassword = $this->passwordHasher->hashPassword($user, $plainPassword);
|
||||||
$entityInstance->setPassword($encodedPassword);
|
$entityInstance->setPassword($hashedPassword);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue