Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3918

How to modify user Information after requiring his password with Symfony 4

$
0
0

I would like to create a page that allows the user to modify his personal infos. I want him to enter his current password to modify any information.

I created a form based on the connected user when the form is submitted and valid, I want to check if the password is valid using the function isPasswordValid() of my passwordEncoder..

My problem is that when this function is called with $user as parameter, it always returns false. I found where this problem comes from, it's because the $user used as parameter as been modified when the form has been submitted. I've tried declaring another variable to stock my Initial User ($dbUser for example) and using another to instance the form but when I dump the $dbUser it has been modified and I don't know why...

The variable shouldn't be changed after the submit because it's never used... I can't find what I doing wrong...

   /**     * @Route("/mes-infos", name="account_infos")     */    public function showMyInfos(Request $request, UserRepository $userRepo)    {        $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');        $user = $this->getUser();        // $dbUser = $userRepo->findOneBy(['id' => 13]);        $form = $this->createForm(UserModificationType::class, $user);        $form->handleRequest($request);        if ($form->isSubmitted() && $form->isValid()) {            $enteredPassword = $request->request->get('user_modification')['plainPassword'];            $passwordEncoder = $this->passwordEncoder;            $manager = $this->getDoctrine()->getManager();            if ($passwordEncoder->isPasswordValid($user, $enteredPassword)) {                dd('it works!!!!!');                // $manager->persist($user);                // $manager->flush();            } else {                dd('It\'s not!!!!');            }        }        return $this->render('account/myaccount-infos.html.twig', ['form' => $form->createView()        ]);    }

Viewing all articles
Browse latest Browse all 3918

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>