|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
-
- namespace Lc\SovBundle\Controller\Admin;
-
- use Lc\SovBundle\Doctrine\EntityManager;
- use Lc\SovBundle\Form\Type\User\ChangePasswordFormType;
- use Lc\SovBundle\Form\Type\User\ProfileFormType;
- use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
-
- 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();
- }
-
- 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('plainPassword')->getData();
-
- // @TODO : créer UserManager
- $newPasswordEncoded = $passwordEncoder->encodePassword($user, $plainPassword);
- $user->setPassword($newPasswordEncoded);
-
- $this->em->update($user);
- $this->em->flush();
- }
-
- return $this->render(
- '@LcSov/user/change_password.html.twig',
- [
- 'form' => $form->createView()
- ]
- );
- }
-
- }
|