Various adjustments

master
Julien Rosset 1 year ago
parent a910962245
commit 9e8133a136

@ -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 {
/**

@ -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');
}
}

@ -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
*

@ -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;
}
/**

@ -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,

@ -5,7 +5,7 @@
{% for flashType, flashMessages in flashes %}
{% for flashMessage in flashMessages %}
<div class="alert alert-{{ flashType }} alert-dismissible fade show" role="{{ flashType }}">
{{ flashMessage }}
{{ flashMessage|raw }}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
{% endfor %}

@ -15,8 +15,35 @@
<!--region menu-->
<nav class="navbar navbar-expand-lg py-0">
<ul class="navbar-nav">
{% if app.user %}
<!--region User menu-->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle py-0" id="dropdown-locale" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
{{ app.user }}
</a>
<ul class="dropdown-menu" aria-labelledby="dropdown-locale">
<li><a href="{{ path('user_signOut') }}" class="dropdown-item">{{ 'pages.signOut'|trans }}</a></li>
</ul>
</li>
<!--endregion-->
{% if is_granted('ROLE_ADMIN') %}
<!--region Administration menu-->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle py-0" id="dropdown-locale" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
{{ 'pages.admin.title'|trans }}
</a>
<ul class="dropdown-menu" aria-labelledby="dropdown-locale">
<li><a href="{{ path('admin_user_list') }}" class="dropdown-item">{{ 'pages.admin.user'|trans }}</a></li>
</ul>
</li>
<!--endregion-->
{% endif %}
{% else %}
<li class="nav-item"><a href="{{ path('user_signIn') }}" class="nav-link py-0">{{ 'pages.signIn.title'|trans }}</a></li>
<li class="nav-item"><a href="{{ path('user_signUp') }}" class="nav-link py-0">{{ 'pages.signUp.title'|trans }}</a></li>
{% endif %}
<!--region Locale choice-->
<li class="nav-item dropdown dropstart">
<a class="nav-link dropdown-toggle py-0" id="dropdown-locale" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<img src="{{ asset('images/freakFlagSprite.png') }}"
@ -39,6 +66,7 @@
{% endfor %}
</ul>
</li>
<!--endregion-->
</ul>
</nav>
<!--endregion-->

@ -4,5 +4,9 @@
{% block mainContent %}
<h1>Web EDM</h1>
{% if app.user %}
Bienvenu {{ app.user }}
{% else %}
{{ 'pages.home.unauthenticatedText'|trans({pathSignIn: path('user_signIn'), pathSignUp: path('user_signUp')})|raw }}
{% endif %}
{% endblock %}

@ -88,6 +88,21 @@ You are already logged in, please <a href="{signOutUrl}">sign out</a> first.
<target>Sign Out</target>
</segment>
</unit>
<group id="admin">
<unit id="title">
<segment>
<source>pages.admin.title</source>
<target>Administration</target>
</segment>
</unit>
<unit id="user">
<segment>
<source>pages.admin.user</source>
<target>Users</target>
</segment>
</unit>
</group>
</group>
<group id="fields">
<group id="email">
@ -170,6 +185,12 @@ You are already logged in, please <a href="{signOutUrl}">sign out</a> first.
</segment>
</unit>
</group>
<unit id="name">
<segment>
<source>fields.name</source>
<target>Nom</target>
</segment>
</unit>
<unit id="signIn">
<segment>
<source>fields.signIn</source>
@ -182,6 +203,24 @@ You are already logged in, please <a href="{signOutUrl}">sign out</a> first.
<target>Sign Up</target>
</segment>
</unit>
<unit id="emailVerify">
<segment>
<source>fields.emailVerify</source>
<target>Email verified</target>
</segment>
</unit>
<unit id="adminValidated">
<segment>
<source>fields.adminValidated</source>
<target>Admin validated</target>
</segment>
</unit>
<unit id="administrator">
<segment>
<source>fields.administrator</source>
<target>Administrator</target>
</segment>
</unit>
</group>
<group id="emails">
<group id="emailConfirmation">

@ -88,6 +88,21 @@ Vous êtes déjà connecté, merci de vous <a href="{signOutUrl}">déconnecter</
<target>Déconnexion</target>
</segment>
</unit>
<group id="admin">
<unit id="title">
<segment>
<source>pages.admin.title</source>
<target>Administration</target>
</segment>
</unit>
<unit id="user">
<segment>
<source>pages.admin.user</source>
<target>Utilisateurs</target>
</segment>
</unit>
</group>
</group>
<group id="fields">
<group id="email">
@ -170,6 +185,12 @@ Vous êtes déjà connecté, merci de vous <a href="{signOutUrl}">déconnecter</
</segment>
</unit>
</group>
<unit id="name">
<segment>
<source>fields.name</source>
<target>Nom</target>
</segment>
</unit>
<unit id="signIn">
<segment>
<source>fields.signIn</source>
@ -182,6 +203,24 @@ Vous êtes déjà connecté, merci de vous <a href="{signOutUrl}">déconnecter</
<target>S'enregistrer</target>
</segment>
</unit>
<unit id="emailVerify">
<segment>
<source>fields.emailVerify</source>
<target>Mail vérifié</target>
</segment>
</unit>
<unit id="adminValidated">
<segment>
<source>fields.adminValidated</source>
<target>Validé admin</target>
</segment>
</unit>
<unit id="administrator">
<segment>
<source>fields.administrator</source>
<target>Administrateur</target>
</segment>
</unit>
</group>
<group id="emails">
<group id="emailConfirmation">

Loading…
Cancel
Save