- Le pseudo et le mail est maintenant unique.
This commit is contained in:
@ -19,6 +19,7 @@
|
|||||||
"symfony/runtime": "7.0.*",
|
"symfony/runtime": "7.0.*",
|
||||||
"symfony/security-bundle": "7.0.*",
|
"symfony/security-bundle": "7.0.*",
|
||||||
"symfony/twig-bundle": "7.0.*",
|
"symfony/twig-bundle": "7.0.*",
|
||||||
|
"symfony/validator": "7.0.*",
|
||||||
"symfony/webpack-encore-bundle": "^2.2",
|
"symfony/webpack-encore-bundle": "^2.2",
|
||||||
"symfony/yaml": "7.0.*",
|
"symfony/yaml": "7.0.*",
|
||||||
"twig/extra-bundle": "^2.12|^3.0",
|
"twig/extra-bundle": "^2.12|^3.0",
|
||||||
|
97
composer.lock
generated
97
composer.lock
generated
@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "c53910010d80c77569e2b6c0828c9aa2",
|
"content-hash": "c7a74db8c19635e6115f7567b0077bb0",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "doctrine/cache",
|
"name": "doctrine/cache",
|
||||||
@ -5374,6 +5374,101 @@
|
|||||||
],
|
],
|
||||||
"time": "2023-11-26T15:16:53+00:00"
|
"time": "2023-11-26T15:16:53+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "symfony/validator",
|
||||||
|
"version": "v7.0.10",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/symfony/validator.git",
|
||||||
|
"reference": "b3e4d838cdae9f2882402c2ad8018a27d469c075"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/symfony/validator/zipball/b3e4d838cdae9f2882402c2ad8018a27d469c075",
|
||||||
|
"reference": "b3e4d838cdae9f2882402c2ad8018a27d469c075",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=8.2",
|
||||||
|
"symfony/polyfill-ctype": "~1.8",
|
||||||
|
"symfony/polyfill-mbstring": "~1.0",
|
||||||
|
"symfony/polyfill-php83": "^1.27",
|
||||||
|
"symfony/translation-contracts": "^2.5|^3"
|
||||||
|
},
|
||||||
|
"conflict": {
|
||||||
|
"doctrine/lexer": "<1.1",
|
||||||
|
"symfony/dependency-injection": "<6.4",
|
||||||
|
"symfony/doctrine-bridge": "<7.0",
|
||||||
|
"symfony/expression-language": "<6.4",
|
||||||
|
"symfony/http-kernel": "<6.4",
|
||||||
|
"symfony/intl": "<6.4",
|
||||||
|
"symfony/property-info": "<6.4",
|
||||||
|
"symfony/translation": "<6.4.3|>=7.0,<7.0.3",
|
||||||
|
"symfony/yaml": "<6.4"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"egulias/email-validator": "^2.1.10|^3|^4",
|
||||||
|
"symfony/cache": "^6.4|^7.0",
|
||||||
|
"symfony/config": "^6.4|^7.0",
|
||||||
|
"symfony/console": "^6.4|^7.0",
|
||||||
|
"symfony/dependency-injection": "^6.4|^7.0",
|
||||||
|
"symfony/expression-language": "^6.4|^7.0",
|
||||||
|
"symfony/finder": "^6.4|^7.0",
|
||||||
|
"symfony/http-client": "^6.4|^7.0",
|
||||||
|
"symfony/http-foundation": "^6.4|^7.0",
|
||||||
|
"symfony/http-kernel": "^6.4|^7.0",
|
||||||
|
"symfony/intl": "^6.4|^7.0",
|
||||||
|
"symfony/mime": "^6.4|^7.0",
|
||||||
|
"symfony/property-access": "^6.4|^7.0",
|
||||||
|
"symfony/property-info": "^6.4|^7.0",
|
||||||
|
"symfony/translation": "^6.4.3|^7.0.3",
|
||||||
|
"symfony/yaml": "^6.4|^7.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Symfony\\Component\\Validator\\": ""
|
||||||
|
},
|
||||||
|
"exclude-from-classmap": [
|
||||||
|
"/Tests/",
|
||||||
|
"/Resources/bin/"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Fabien Potencier",
|
||||||
|
"email": "fabien@symfony.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Symfony Community",
|
||||||
|
"homepage": "https://symfony.com/contributors"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Provides tools to validate values",
|
||||||
|
"homepage": "https://symfony.com",
|
||||||
|
"support": {
|
||||||
|
"source": "https://github.com/symfony/validator/tree/v7.0.10"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://symfony.com/sponsor",
|
||||||
|
"type": "custom"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/fabpot",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||||
|
"type": "tidelift"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2024-07-26T12:31:22+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/var-dumper",
|
"name": "symfony/var-dumper",
|
||||||
"version": "v7.0.2",
|
"version": "v7.0.2",
|
||||||
|
@ -9,16 +9,19 @@ use Symfony\Component\HttpFoundation\Response;
|
|||||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
|
|
||||||
class RegistrationController extends AbstractController
|
class RegistrationController extends AbstractController
|
||||||
{
|
{
|
||||||
private $entityManager;
|
private $entityManager;
|
||||||
private $passwordHasher;
|
private $passwordHasher;
|
||||||
|
private $validator;
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $entityManager, UserPasswordHasherInterface $passwordHasher)
|
public function __construct(EntityManagerInterface $entityManager, UserPasswordHasherInterface $passwordHasher, ValidatorInterface $validator)
|
||||||
{
|
{
|
||||||
$this->entityManager = $entityManager;
|
$this->entityManager = $entityManager;
|
||||||
$this->passwordHasher = $passwordHasher;
|
$this->passwordHasher = $passwordHasher;
|
||||||
|
$this->validator = $validator;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/registration', name: 'app_registration')]
|
#[Route('/registration', name: 'app_registration')]
|
||||||
@ -28,7 +31,18 @@ class RegistrationController extends AbstractController
|
|||||||
$form = $this->createForm(RegistrationType::class, $user);
|
$form = $this->createForm(RegistrationType::class, $user);
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted()) {
|
||||||
|
$existingEmail = $this->entityManager->getRepository(User::class)->findOneBy(['email' => $user->getEmail()]);
|
||||||
|
$existingPseudo = $this->entityManager->getRepository(User::class)->findOneBy(['pseudo' => $user->getPseudo()]);
|
||||||
|
|
||||||
|
if ($existingEmail) {
|
||||||
|
$form->get('email')->addError(new \Symfony\Component\Form\FormError('Cet email est déjà utilisé.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($existingPseudo) {
|
||||||
|
$form->get('pseudo')->addError(new \Symfony\Component\Form\FormError('Ce pseudo est déjà pris.'));
|
||||||
|
}
|
||||||
|
|
||||||
$plainPassword = $user->getPassword();
|
$plainPassword = $user->getPassword();
|
||||||
$confirmPassword = $form->get('confirmPassword')->getData();
|
$confirmPassword = $form->get('confirmPassword')->getData();
|
||||||
|
|
||||||
@ -37,14 +51,23 @@ class RegistrationController extends AbstractController
|
|||||||
return $this->redirectToRoute('app_registration');
|
return $this->redirectToRoute('app_registration');
|
||||||
}
|
}
|
||||||
|
|
||||||
$hashedPassword = $this->passwordHasher->hashPassword($user, $plainPassword);
|
$errors = $this->validator->validate($user);
|
||||||
$user->setPassword($hashedPassword);
|
if (count($errors) > 0) {
|
||||||
|
foreach ($errors as $error) {
|
||||||
|
$form->addError(new \Symfony\Component\Form\FormError($error->getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->entityManager->persist($user);
|
if ($form->isValid()) {
|
||||||
$this->entityManager->flush();
|
$hashedPassword = $this->passwordHasher->hashPassword($user, $plainPassword);
|
||||||
|
$user->setPassword($hashedPassword);
|
||||||
|
|
||||||
$this->addFlash('success', 'Votre compte a été créé avec succès !');
|
$this->entityManager->persist($user);
|
||||||
return $this->redirectToRoute('home');
|
$this->entityManager->flush();
|
||||||
|
|
||||||
|
$this->addFlash('success', 'Votre compte a été créé avec succès !');
|
||||||
|
return $this->redirectToRoute('home');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('registration/index.html.twig', [
|
return $this->render('registration/index.html.twig', [
|
||||||
|
12
symfony.lock
12
symfony.lock
@ -135,6 +135,18 @@
|
|||||||
"templates/base.html.twig"
|
"templates/base.html.twig"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"symfony/validator": {
|
||||||
|
"version": "7.0",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "main",
|
||||||
|
"version": "7.0",
|
||||||
|
"ref": "8c1c4e28d26a124b0bb273f537ca8ce443472bfd"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"config/packages/validator.yaml"
|
||||||
|
]
|
||||||
|
},
|
||||||
"symfony/web-profiler-bundle": {
|
"symfony/web-profiler-bundle": {
|
||||||
"version": "7.0",
|
"version": "7.0",
|
||||||
"recipe": {
|
"recipe": {
|
||||||
|
@ -28,17 +28,29 @@
|
|||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
{{ form_label(form.pseudo, 'Pseudo', {'label_attr': {'class': 'block text-sm font-medium text-gray-700'}}) }}
|
{{ form_label(form.pseudo, 'Pseudo', {'label_attr': {'class': 'block text-sm font-medium text-gray-700'}}) }}
|
||||||
<div class="mt-1">
|
<div class="mt-1">
|
||||||
{{ form_widget(form.pseudo, {'attr': {'class': 'w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm'}}) }}
|
{{ form_widget(form.pseudo, {
|
||||||
|
'attr': {
|
||||||
|
'class': form.pseudo.vars.errors|length > 0 ? 'w-full px-3 py-2 border border-red-500 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm' : 'w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm'
|
||||||
|
}
|
||||||
|
}) }}
|
||||||
|
</div>
|
||||||
|
<div class="text-sm text-red-600 mt-2">
|
||||||
|
{{ form_errors(form.pseudo) }}
|
||||||
</div>
|
</div>
|
||||||
{{ form_errors(form.pseudo) }}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
{{ form_label(form.email, 'Email', {'label_attr': {'class': 'block text-sm font-medium text-gray-700'}}) }}
|
{{ form_label(form.email, 'Email', {'label_attr': {'class': 'block text-sm font-medium text-gray-700'}}) }}
|
||||||
<div class="mt-1">
|
<div class="mt-1">
|
||||||
{{ form_widget(form.email, {'attr': {'class': 'w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm'}}) }}
|
{{ form_widget(form.email, {
|
||||||
|
'attr': {
|
||||||
|
'class': form.email.vars.errors|length > 0 ? 'w-full px-3 py-2 border border-red-500 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm' : 'w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm'
|
||||||
|
}
|
||||||
|
}) }}
|
||||||
|
</div>
|
||||||
|
<div class="text-sm text-red-600 mt-2">
|
||||||
|
{{ form_errors(form.email) }}
|
||||||
</div>
|
</div>
|
||||||
{{ form_errors(form.email) }}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
|
Reference in New Issue
Block a user