diff --git a/src/Controller/CoreController.php b/src/Controller/CoreController.php index 064d9bb..1b3a956 100644 --- a/src/Controller/CoreController.php +++ b/src/Controller/CoreController.php @@ -8,7 +8,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; /** - * Controller for core page : home, etc. + * Controllers for "core" pages: home, etc. */ class CoreController extends AbstractController { /** diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 330ee45..1354da1 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -20,6 +20,10 @@ use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; use Symfony\Contracts\Translation\TranslatorInterface; use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailExceptionInterface; +/** + * Controllers for user pages + */ +#[Route('/user')] class UserController extends AbstractController { /** * @var TranslatorInterface The translator service @@ -54,6 +58,10 @@ class UserController extends AbstractController { */ #[Route('/signUp', name: 'user_signUp')] public function signUp (Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager): Response { + if (($response = $this->checkUserNotConnected())) { + return $response; + } + $user = new User(); $form = $this->createForm(SignUpFormType::class, $user); @@ -144,18 +152,8 @@ class UserController extends AbstractController { */ #[Route(path: '/signIn', name: 'user_signIn')] public function login (AuthenticationUtils $authenticationUtils): Response { - /** @var User|null $user */ - $user = $this->getUser(); - if ($user !== null) { - $this->addFlash( - 'warning', - $this->translator->trans( - 'pages.emailVerify.warningAlreadyConnected', - [ - 'signOutUrl' => $this->generateUrl('user_signOut'), - ] - ) - ); + if (($response = $this->checkUserNotConnected())) { + return $response; } if (($error = $authenticationUtils->getLastAuthenticationError()) !== null) { @@ -180,4 +178,28 @@ class UserController extends AbstractController { public function logout (): void { throw new LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.'); } + + /** + * Check the user is NOT connected + * + * @return Response|null The response (warning and redirect) if user is connected, else Null + */ + private function checkUserNotConnected (): ?Response { + /** @var User|null $user */ + $user = $this->getUser(); + if ($user === null) { + return null; + } + + $this->addFlash( + 'warning', + $this->translator->trans( + 'pages.emailVerify.warningAlreadyConnected', + [ + 'signOutUrl' => $this->generateUrl('user_signOut'), + ] + ) + ); + return $this->redirectToRoute('core_main'); + } } diff --git a/src/Entity/TEntityBase.php b/src/Entity/TEntityBase.php index 84c8ad7..56ed43d 100644 --- a/src/Entity/TEntityBase.php +++ b/src/Entity/TEntityBase.php @@ -6,6 +6,7 @@ use DateTimeInterface; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Gedmo\Mapping\Annotation as Gedmo; +use JsonSerializable; /** * Implementation for the base implementation of an entity: id, creation and last update date and time @@ -34,6 +35,23 @@ trait TEntityBase { #[Gedmo\Timestampable(on: 'update')] private ?DateTimeInterface $lastModification = null; + /** + * Les données du trait qui doivent être inclus dans le JSON + * + * @return array Les données du trait qui doivent être inclus dans le JSON + * + * @see JsonSerializable::jsonSerialize() + * + * @noinspection PhpMethodNamingConventionInspection + */ + protected final function TEntityBase__jsonSerialize (): array { + return [ + 'id' => $this->getId(), + 'creation' => $this->getCreation()?->format(DateTimeInterface::RFC3339), + 'lastModification' => $this->getLastModification()?->format(DateTimeInterface::RFC3339), + ]; + } + /** * The internal id * diff --git a/src/Entity/User.php b/src/Entity/User.php index 600942d..07e130b 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -8,6 +8,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; +use Stringable; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\UserInterface; @@ -18,7 +19,7 @@ use Symfony\Component\Validator\Constraints as Assert; */ #[ORM\Entity(repositoryClass: UserRepository::class)] #[UniqueEntity(fields: ['email'], message: 'fields.email.errorUnique')] -class User implements UserInterface, PasswordAuthenticatedUserInterface { +class User implements UserInterface, PasswordAuthenticatedUserInterface, Stringable { use TEntityBase; /** @@ -77,6 +78,12 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface { public function __construct () { $this->tags = new ArrayCollection(); } + /** + * @inheritDoc + */ + public function __toString (): string { + return $this->getName() ?? $this->getEmail(); + } /** * The email @@ -231,8 +238,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface { * * @see self::validate() */ - public function getValidationAdministrator (): ?self - { + public function getValidationAdministrator (): ?self { return $this->validationAdministrator; } /** @@ -242,8 +248,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface { * * @see self::validate() */ - public function getValidationDate (): ?DateTimeImmutable - { + public function getValidationDate (): ?DateTimeImmutable { return $this->validationDate; } /** diff --git a/src/Form/SignUpFormType.php b/src/Form/SignUpFormType.php index 7942f03..b744a61 100644 --- a/src/Form/SignUpFormType.php +++ b/src/Form/SignUpFormType.php @@ -37,6 +37,9 @@ class SignUpFormType extends AbstractType { ->add('email', null, [ 'label' => 'fields.email.label', ]) + ->add('name', null, [ + 'label' => 'fields.name', + ]) ->add('newPassword', RepeatedType::class, [ 'type' => PasswordType::class, 'mapped' => false, diff --git a/templates/_flashes.html.twig b/templates/_flashes.html.twig index a9a0988..fe57979 100644 --- a/templates/_flashes.html.twig +++ b/templates/_flashes.html.twig @@ -5,7 +5,7 @@ {% for flashType, flashMessages in flashes %} {% for flashMessage in flashMessages %}
- {{ flashMessage }} + {{ flashMessage|raw }}
{% endfor %} diff --git a/templates/base.html.twig b/templates/base.html.twig index e830643..88276f2 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -15,8 +15,35 @@ sign out first. Sign Out + + + + + pages.admin.title + Administration + + + + + pages.admin.user + Users + + + @@ -170,6 +185,12 @@ You are already logged in, please sign out first. + + + fields.name + Nom + + fields.signIn @@ -182,6 +203,24 @@ You are already logged in, please sign out first. Sign Up + + + fields.emailVerify + Email verified + + + + + fields.adminValidated + Admin validated + + + + + fields.administrator + Administrator + + diff --git a/translations/messages+intl-icu.fr.xlf b/translations/messages+intl-icu.fr.xlf index da734ed..8e1a54c 100644 --- a/translations/messages+intl-icu.fr.xlf +++ b/translations/messages+intl-icu.fr.xlf @@ -88,6 +88,21 @@ Vous êtes déjà connecté, merci de vous déconnecterDéconnexion + + + + + pages.admin.title + Administration + + + + + pages.admin.user + Utilisateurs + + + @@ -170,6 +185,12 @@ Vous êtes déjà connecté, merci de vous déconnecter + + + fields.name + Nom + + fields.signIn @@ -182,6 +203,24 @@ Vous êtes déjà connecté, merci de vous déconnecterS'enregistrer + + + fields.emailVerify + Mail vérifié + + + + + fields.adminValidated + Validé admin + + + + + fields.administrator + Administrateur + +