88 lines
3.6 KiB
PHP
88 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Dto\Profils\DtoForm;
|
|
use App\Dto\Profils\DtoPassword;
|
|
use App\Dto\Profils\DtoPasswordForm;
|
|
use App\Dto\Profils\DtoProfils;
|
|
use App\Entity\Account;
|
|
use App\Entity\AccountResetPasswordRequest;
|
|
use App\Entity\Sub;
|
|
use App\Form\RequestPasswordConfirmType;
|
|
use App\Form\RequestPasswordRequestType;
|
|
use App\Repository\SubRepository;
|
|
use App\Service\Mailer\Mailer;
|
|
use App\Service\ResetPassword\Event\ResetPasswordConfirmEvent;
|
|
use App\Service\ResetPassword\Event\ResetPasswordEvent;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Psr\EventDispatcher\EventDispatcherInterface;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
|
use Twig\Environment;
|
|
|
|
class ProfilsController extends AbstractController
|
|
{
|
|
|
|
#[Route(path: '/profils', name: 'app_profile', options: ['sitemap' => false], methods: ['POST','GET'])]
|
|
public function notificationSub(Request $request,UserPasswordHasherInterface $userPasswordHasher,EntityManagerInterface $entityManager,Mailer $mailer): Response
|
|
{
|
|
if(!$this->isGranted('ROLE_USER'))
|
|
return $this->render('error/forbidden.twig',[
|
|
'no_index' =>true
|
|
]);
|
|
[$formProfils,$response] = $this->handleProfils($this->getUser(),$request,$entityManager,$mailer);
|
|
if(!is_null($response)){
|
|
return $response;
|
|
}
|
|
[$formPassword,$response] = $this->handlePassword($this->getUser(),$request,$userPasswordHasher,$entityManager,$mailer);
|
|
if(!is_null($response)){
|
|
return $response;
|
|
}
|
|
return $this->render('profis/index.twig', [
|
|
'formProfils' => $formProfils,
|
|
'formPassword' => $formPassword,
|
|
'formDelete' => '',
|
|
'no_index'
|
|
]);
|
|
}
|
|
|
|
private function handleProfils(?\Symfony\Component\Security\Core\User\UserInterface $getUser, Request $request, EntityManagerInterface $entityManager, Mailer $mailer)
|
|
{
|
|
$oldEmail = $getUser->getEmail();
|
|
$dto = new DtoProfils($getUser);
|
|
$form = $this->createForm(DtoForm::class,$dto);
|
|
$form->handleRequest($request);
|
|
if($form->isSubmitted() && $form->isValid()){
|
|
$getUser->setEmail($dto->getEmail());
|
|
$getUser->setUsername($dto->getUsername());
|
|
$entityManager->persist($getUser);
|
|
$entityManager->flush();
|
|
return [$form->createView(),$this->redirectToRoute('app_profile',['updateProfils'=>true])];
|
|
}
|
|
return [$form->createView(),null];
|
|
}
|
|
|
|
private function handlePassword(?\Symfony\Component\Security\Core\User\UserInterface $getUser, Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, Mailer $mailer)
|
|
{
|
|
$dto = new DtoPassword();
|
|
$form = $this->createForm(DtoPasswordForm::class,$dto);
|
|
$form->handleRequest($request);
|
|
if($form->isSubmitted() && $form->isValid()){
|
|
$getUser->setPassword($userPasswordHasher->hashPassword($dto->getPassword(), $getUser));
|
|
$entityManager->persist($getUser);
|
|
$entityManager->flush();
|
|
return [$form->createView(),$this->redirectToRoute('app_profile',['updatePassword'=>true])];
|
|
}
|
|
return [$form->createView(),null];
|
|
}
|
|
|
|
}
|
|
|