I create form bundle user in Symfony 3.4
everything works fine .my register form works. and I can register the user .and I can login too. I try to create edit form for member .i cannot edit password member. I read this post but I have not any result ..anyone knows where is my wrong
it is my user entity
/**
* @Assert\NotBlank()
* @Assert\Length(max=4096)
*/
private $plainPassword;
/**
* The below length depends on the "algorithm" you use for encoding
* the password, but this works well with bcrypt.
*
* @ORM\Column(type="string", length=64)
*/
private $password;
public function getPlainPassword()
{
return $this->plainPassword;
}
public function setPlainPassword($password)
{
$this->plainPassword = $password;
}
public function getPassword()
{
return $this->password;
}
public function setPassword($password)
{
$this->password = $password;
}
public function eraseCredentials()
{
}
UserType
.
.
.
->add('oldPlainPassword', \Symfony\Component\Form\Extension\Core\Type\PasswordType::class, array(
'constraints' => array(
new \Symfony\Component\Security\Core\Validator\Constraints\UserPassword(),
),
'mapped' => false,
'required' => true,
'label' => 'Current Password',
))
->add('plainPassword', RepeatedType::class, array(
'type' => PasswordType::class,
'first_options' => array('label' => 'Password'),
'second_options' => array('label' => 'Repeat Password'),
))
;
}
.
.
.
my controller
.
.
.
/**
* @Route("/admin__/EditUser/{id}" ,name="editUser")
*/
public function EditUserAction(Request $request, $id)
{
.
.
.
if ($request->getMethod() == Request::METHOD_POST){
$form->handleRequest($request);
.
.
.
$password = $passwordEncoder->encodePassword($user, $user->getPlainPassword());
$user->setPassword($password);
.
.
.
$em->flush();
edit_user.html.twig
{{ form_row(form.plainPassword.second) }}
{{ form_row(form.plainPassword.first) }}
{{ form_row(form.oldPlainPassword) }}