Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @Route("/admin/users/edit/{id}", requirements={"id" = "d+"}, name="admin_users_edit")
- * @Template("@Core/admin/users_edit.html.twig")
- * @Security("has_role('ROLE_ADMIN')")
- */
- public function EditUserAction($id, Request $request, UserPasswordEncoderInterface $passwordEncoder)
- {
- $user = $this->getDoctrine()->getRepository('CoreBundle:User')->findOneBy([ 'id'=>$id, 'deleted' => 0 ]);
- if ( $user )
- {
- $old_password = $user->getPassword();
- $form = $this->createForm(UserType::class, $user);
- $form->handleRequest($request);
- if ($form->isSubmitted() && $form->isValid())
- {
- // If admin changed the user password
- if ( $user->getPlainPassword() )
- {
- $password = $passwordEncoder->encodePassword($user, $user->getPlainPassword());
- $user->setPassword($password);
- }
- // If admin didn't change the user password, we persist the old one
- else
- {
- $user->setPassword($old_password);
- }
- $entityManager = $this->getDoctrine()->getManager();
- $entityManager->persist($user);
- $entityManager->flush();
- }
- return array('form' => $form->createView());
- }
- return $this->redirectToRoute('admin_users');
- }
Add Comment
Please, Sign In to add comment