|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
-
- namespace Lc\SovBundle\Controller\Admin;
-
- use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
- use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
- use Lc\SovBundle\Doctrine\EntityManager;
- use Lc\SovBundle\Form\Type\User\ChangePasswordFormType;
- use Lc\SovBundle\Form\Type\User\ProfileFormType;
- use Lc\SovBundle\Model\User\User;
- use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
- use Symfony\Component\Translation\TranslatableMessage;
-
- class UserController extends AbstractController
- {
- protected $em;
-
- public function __construct(EntityManager $em)
- {
- $this->em = $em;
- }
-
- public function profile(Request $request): Response
- {
- $user = $this->getUser();
- $form = $this->createForm(ProfileFormType::class, $user);
-
- $form->handleRequest($request);
-
- if ($form->isSubmitted() && $form->isValid()) {
- $user = $form->getData();
-
- $this->em->update($user);
- $this->em->flush();
-
- $this->addFlash('success', new TranslatableMessage('form.account_profile.message.success', [], 'admin'));
- }
-
- return $this->render(
- '@LcSov/user/profile.html.twig',
- [
- 'form' => $form->createView(),
- ]
- );
- }
-
- public function changePassword(Request $request, UserPasswordEncoderInterface $passwordEncoder): Response
- {
- $user = $this->getUser();
- $form = $this->createForm(ChangePasswordFormType::class, $user);
-
- $form->handleRequest($request);
-
- if ($form->isSubmitted() && $form->isValid()) {
- $user = $form->getData();
-
- $plainPassword = $form->get('plain_password')->getData();
-
- // @TODO : créer UserManager
- $newPasswordEncoded = $passwordEncoder->encodePassword($user, $plainPassword);
- $user->setPassword($newPasswordEncoded);
-
- $this->em->update($user);
- $this->em->flush();
-
- $this->addFlash('success', new TranslatableMessage('form.account_password.message.success', [], 'admin'));
- }
-
- return $this->render(
- '@LcSov/user/change_password.html.twig',
- [
- 'entity_class' => User::class,
- 'form' => $form->createView()
- ]
- );
- }
-
- }
|