profile update done
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Participant;
|
||||
use App\Form\ProfileFormType;
|
||||
use App\Service\FileUploader;
|
||||
use App\Form\RegistrationFormType;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
@@ -20,7 +21,7 @@ class ProfileController extends AbstractController
|
||||
$this->profileRepo = $profileRepo;
|
||||
}
|
||||
#[Route('/profile/{uuid}', name: 'profile_view', methods: ['GET'])]
|
||||
public function viewProfile(string $uuid, ParticipantRepository $profileRepo): Response
|
||||
public function viewProfile(string $uuid, ParticipantRepository $profileRepo, Request $request): Response
|
||||
{
|
||||
$currentProfile = $profileRepo->findOneBy(['idParticipant' => $uuid]);
|
||||
return $this->render('profile/view.html.twig', [
|
||||
@@ -37,7 +38,7 @@ class ProfileController extends AbstractController
|
||||
$this->addFlash('error', "Vous ne pouvez pas modifier un profil qui n'est pas le votre");
|
||||
return $this->redirectToRoute('profile_view',['uuid' => $profile->getIdParticipant()]);
|
||||
}
|
||||
$form = $this->createForm(RegistrationFormType::class, $profile);
|
||||
$form = $this->createForm(ProfileFormType::class, $profile);
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$imageFile = $form->get('image')->getData();
|
||||
@@ -47,7 +48,34 @@ class ProfileController extends AbstractController
|
||||
$imageFilename = $this->fileUploader->upload($imageFile);
|
||||
$profile->setFileName($imageFilename);
|
||||
} else {
|
||||
$profile->setFileName('');
|
||||
$profile->setFileName(null);
|
||||
}
|
||||
}
|
||||
if ($form->has('newPassword') && $form->has('confirmPassword')) {
|
||||
if ($form->get('newPassword')->getData() !== $form->get('confirmPassword')->getData()) {
|
||||
$this->addFlash('error', "Les mots de passe ne correspondent pas");
|
||||
return $this->render('profile/edit.html.twig', [
|
||||
'formProfile' => $form,
|
||||
]);
|
||||
}
|
||||
$profile->setPassword($form->get('newPassword')->getData());
|
||||
}
|
||||
if ($form->has('pseudo')) {
|
||||
$alreadyExists = $this->profileRepo->findOneBy(['pseudo' => $profile->getPseudo()]);
|
||||
if ($alreadyExists && $alreadyExists !== $profile) {
|
||||
$this->addFlash('error', "Ce pseudo existe déjà");
|
||||
return $this->render('profile/edit.html.twig', [
|
||||
'formProfile' => $form,
|
||||
]);
|
||||
}
|
||||
}
|
||||
if ($form->has('email')) {
|
||||
$alreadyExists = $this->profileRepo->findOneBy(['email' => $profile->getEmail()]);
|
||||
if ($alreadyExists && $alreadyExists !== $profile) {
|
||||
$this->addFlash('error', "Cet email existe déjà");
|
||||
return $this->render('profile/edit.html.twig', [
|
||||
'formProfile' => $form,
|
||||
]);
|
||||
}
|
||||
}
|
||||
$profileToUpdate = $this->profileRepo->update($profile);
|
||||
@@ -61,7 +89,7 @@ class ProfileController extends AbstractController
|
||||
'formProfile' => $form,
|
||||
]);
|
||||
} catch(\Exception $e) {
|
||||
$formProfile = $this->createForm(RegistrationFormType::class, $profile);
|
||||
$formProfile = $this->createForm(ProfileFormType::class, $profile);
|
||||
$this->addFlash('error', $e->getMessage());
|
||||
return $this->render('profile/edit.html.twig', ['formProfile' => $formProfile]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user