You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.4KB

  1. <?php
  2. namespace Lc\SovBundle\Controller\User;
  3. use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
  4. use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
  5. use Lc\SovBundle\Doctrine\EntityManager;
  6. use Lc\SovBundle\Form\User\ChangePasswordFormType;
  7. use Lc\SovBundle\Form\User\ProfileFormType;
  8. use Lc\SovBundle\Form\User\UserMerchantFormType;
  9. use Lc\SovBundle\Model\User\User;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  14. use Symfony\Component\Translation\TranslatableMessage;
  15. class AccountAdminController extends AbstractController
  16. {
  17. protected $em;
  18. public function __construct(EntityManager $em)
  19. {
  20. $this->em = $em;
  21. }
  22. public function profile(Request $request): Response
  23. {
  24. $user = $this->getUser();
  25. $form = $this->createForm(ProfileFormType::class, $user);
  26. $form->handleRequest($request);
  27. if ($form->isSubmitted() && $form->isValid()) {
  28. $user = $form->getData();
  29. $this->em->update($user);
  30. $this->em->flush();
  31. $this->addFlash('success', new TranslatableMessage('form.account_profile.message.success', [], 'admin'));
  32. }
  33. return $this->render(
  34. '@LcSov/user/profile.html.twig',
  35. [
  36. 'form' => $form->createView(),
  37. ]
  38. );
  39. }
  40. public function changePassword(Request $request, UserPasswordEncoderInterface $passwordEncoder): Response
  41. {
  42. $user = $this->getUser();
  43. $form = $this->createForm(ChangePasswordFormType::class, $user);
  44. $form->handleRequest($request);
  45. if ($form->isSubmitted() && $form->isValid()) {
  46. $user = $form->getData();
  47. $plainPassword = $form->get('plain_password')->getData();
  48. $user->setPassword($passwordEncoder->encodePassword($user, $plainPassword));
  49. $this->em->update($user);
  50. $this->em->flush();
  51. $this->addFlash('success', new TranslatableMessage('form.account_password.message.success', [], 'admin'));
  52. }
  53. return $this->render(
  54. '@LcSov/user/change_password.html.twig',
  55. [
  56. 'entity_class' => User::class,
  57. 'form' => $form->createView()
  58. ]
  59. );
  60. }
  61. }