Signup Good

This commit is contained in:
ExostFlash 2023-11-21 14:49:29 +01:00
parent 8e08cca74f
commit 15361f28cd
8 changed files with 93 additions and 52 deletions

View file

@ -26,6 +26,7 @@
"symfony/mime": "6.1.*", "symfony/mime": "6.1.*",
"symfony/monolog-bundle": "^3.0", "symfony/monolog-bundle": "^3.0",
"symfony/notifier": "6.1.*", "symfony/notifier": "6.1.*",
"symfony/password-hasher": "6.1.*",
"symfony/process": "6.1.*", "symfony/process": "6.1.*",
"symfony/property-access": "6.1.*", "symfony/property-access": "6.1.*",
"symfony/property-info": "6.1.*", "symfony/property-info": "6.1.*",

2
composer.lock generated
View file

@ -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": "8c1abe2e8026fc52bc20a96868b85bcf", "content-hash": "989072ca54ad28f1eb15250b46306f66",
"packages": [ "packages": [
{ {
"name": "doctrine/cache", "name": "doctrine/cache",

View file

@ -1,39 +1,39 @@
security: security:
# https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords # https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords
password_hashers: password_hashers:
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto' Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: "auto"
# https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider # https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
providers: providers:
users_in_memory: { memory: null } users_in_memory: { memory: null }
firewalls: firewalls:
dev: dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/ pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false security: false
main: main:
lazy: true lazy: true
provider: users_in_memory provider: users_in_memory
# activate different ways to authenticate # activate different ways to authenticate
# https://symfony.com/doc/current/security.html#the-firewall # https://symfony.com/doc/current/security.html#the-firewall
# https://symfony.com/doc/current/security/impersonating_user.html # https://symfony.com/doc/current/security/impersonating_user.html
# switch_user: true # switch_user: true
# Easy way to control access for large sections of your site # Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used # Note: Only the *first* access control that matches will be used
access_control: access_control:
# - { path: ^/admin, roles: ROLE_ADMIN } # - { path: ^/admin, roles: ROLE_ADMIN }
# - { path: ^/profile, roles: ROLE_USER } # - { path: ^/profile, roles: ROLE_USER }
when@test: when@test:
security: security:
password_hashers: password_hashers:
# By default, password hashers are resource intensive and take time. This is # By default, password hashers are resource intensive and take time. This is
# important to generate secure password hashes. In tests however, secure hashes # important to generate secure password hashes. In tests however, secure hashes
# are not important, waste resources and increase test times. The following # are not important, waste resources and increase test times. The following
# reduces the work factor to the lowest possible values. # reduces the work factor to the lowest possible values.
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface:
algorithm: auto algorithm: auto
cost: 4 # Lowest possible value for bcrypt cost: 4 # Lowest possible value for bcrypt
time_cost: 3 # Lowest possible value for argon time_cost: 3 # Lowest possible value for argon
memory_cost: 10 # Lowest possible value for argon memory_cost: 10 # Lowest possible value for argon

View file

@ -2,7 +2,13 @@
namespace App\Controller; namespace App\Controller;
use App\Entity\User;
use App\Form\UserSignupType;
use App\Form\UserLoginType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
@ -17,10 +23,32 @@ class UserController extends AbstractController
} }
#[Route('/user/signup', name: 'app_user_signup')] #[Route('/user/signup', name: 'app_user_signup')]
public function signup(): Response public function signup(Request $request, EntityManagerInterface $entityManager): Response
{ {
$user_entity = new User(); // Remplacez par votre entité User
$form = $this->createForm(UserSignupType::class, $user_entity);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// Récupération du mot de passe en clair depuis le formulaire
$plainPassword = $form->get('mdp')->getData();
// Encodage sécurisé du mot de passe
$hashedPassword = password_hash($plainPassword, PASSWORD_DEFAULT);
// Définition du mot de passe haché sur l'entité User
$user_entity->setMdp($hashedPassword);
// Enregistrement de l'utilisateur
$entityManager->persist($user_entity);
$entityManager->flush();
// Redirection après l'enregistrement
return $this->redirectToRoute('app_user_login');
}
return $this->render('user/signup.html.twig', [ return $this->render('user/signup.html.twig', [
'controller_name' => 'UserController', 'form' => $form->createView(),
]); ]);
} }

View file

@ -6,20 +6,15 @@ use App\Entity\User;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
class UserLoginType extends AbstractType class UserLoginType extends AbstractType
{ {
public function buildForm(FormBuilderInterface $builder, array $options): void public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
$builder $builder
->add('name')
->add('fullname')
->add('grade')
->add('mail') ->add('mail')
->add('mdp') ->add('mdp', PasswordType::class);
->add('address')
->add('id_resto')
;
} }
public function configureOptions(OptionsResolver $resolver): void public function configureOptions(OptionsResolver $resolver): void

View file

@ -6,20 +6,28 @@ use App\Entity\User;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
class UserSignupType extends AbstractType class UserSignupType extends AbstractType
{ {
public function buildForm(FormBuilderInterface $builder, array $options): void public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
$builder $builder
->add('name') ->add('name', null, [
->add('fullname') 'attr' => ['placeholder' => 'Entrez votre nom de famille']
->add('grade') ])
->add('mail') ->add('fullname', null, [
->add('mdp') 'attr' => ['placeholder' => 'Entrez votre prénom']
->add('address') ])
->add('id_resto') ->add('mail', null, [
; 'attr' => ['placeholder' => 'exemple@exostflash.ovh']
])
->add('mdp', PasswordType::class, [
'attr' => ['placeholder' => 'Entrez votre mot de passe']
])
->add('address', null, [
'attr' => ['placeholder' => '265 chemin de l\'exemple, 31840 Exemple']
]);
} }
public function configureOptions(OptionsResolver $resolver): void public function configureOptions(OptionsResolver $resolver): void

View file

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="fr">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>McDo : {% block title %}{% endblock %}</title> <title>McDo : {% block title %}{% endblock %}</title>

View file

@ -7,5 +7,14 @@
<div> <div>
<h1>Signup !</h1> <h1>Signup !</h1>
<article>
{{ form_start(form) }}
{{ form_widget(form) }}
<button class="btn">
{{ button_label|default('Save') }}
</button>
{{ form_end(form) }}
</article>
</div> </div>
{% endblock %} {% endblock %}