Signup Good
This commit is contained in:
parent
8e08cca74f
commit
15361f28cd
8 changed files with 93 additions and 52 deletions
|
|
@ -26,6 +26,7 @@
|
|||
"symfony/mime": "6.1.*",
|
||||
"symfony/monolog-bundle": "^3.0",
|
||||
"symfony/notifier": "6.1.*",
|
||||
"symfony/password-hasher": "6.1.*",
|
||||
"symfony/process": "6.1.*",
|
||||
"symfony/property-access": "6.1.*",
|
||||
"symfony/property-info": "6.1.*",
|
||||
|
|
|
|||
2
composer.lock
generated
2
composer.lock
generated
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "8c1abe2e8026fc52bc20a96868b85bcf",
|
||||
"content-hash": "989072ca54ad28f1eb15250b46306f66",
|
||||
"packages": [
|
||||
{
|
||||
"name": "doctrine/cache",
|
||||
|
|
|
|||
|
|
@ -1,39 +1,39 @@
|
|||
security:
|
||||
# https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords
|
||||
password_hashers:
|
||||
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
|
||||
# https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
|
||||
providers:
|
||||
users_in_memory: { memory: null }
|
||||
firewalls:
|
||||
dev:
|
||||
pattern: ^/(_(profiler|wdt)|css|images|js)/
|
||||
security: false
|
||||
main:
|
||||
lazy: true
|
||||
provider: users_in_memory
|
||||
# https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords
|
||||
password_hashers:
|
||||
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: "auto"
|
||||
# https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
|
||||
providers:
|
||||
users_in_memory: { memory: null }
|
||||
firewalls:
|
||||
dev:
|
||||
pattern: ^/(_(profiler|wdt)|css|images|js)/
|
||||
security: false
|
||||
main:
|
||||
lazy: true
|
||||
provider: users_in_memory
|
||||
|
||||
# activate different ways to authenticate
|
||||
# https://symfony.com/doc/current/security.html#the-firewall
|
||||
# activate different ways to authenticate
|
||||
# https://symfony.com/doc/current/security.html#the-firewall
|
||||
|
||||
# https://symfony.com/doc/current/security/impersonating_user.html
|
||||
# switch_user: true
|
||||
# https://symfony.com/doc/current/security/impersonating_user.html
|
||||
# switch_user: true
|
||||
|
||||
# Easy way to control access for large sections of your site
|
||||
# Note: Only the *first* access control that matches will be used
|
||||
access_control:
|
||||
# - { path: ^/admin, roles: ROLE_ADMIN }
|
||||
# - { path: ^/profile, roles: ROLE_USER }
|
||||
# Easy way to control access for large sections of your site
|
||||
# Note: Only the *first* access control that matches will be used
|
||||
access_control:
|
||||
# - { path: ^/admin, roles: ROLE_ADMIN }
|
||||
# - { path: ^/profile, roles: ROLE_USER }
|
||||
|
||||
when@test:
|
||||
security:
|
||||
password_hashers:
|
||||
# By default, password hashers are resource intensive and take time. This is
|
||||
# important to generate secure password hashes. In tests however, secure hashes
|
||||
# are not important, waste resources and increase test times. The following
|
||||
# reduces the work factor to the lowest possible values.
|
||||
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface:
|
||||
algorithm: auto
|
||||
cost: 4 # Lowest possible value for bcrypt
|
||||
time_cost: 3 # Lowest possible value for argon
|
||||
memory_cost: 10 # Lowest possible value for argon
|
||||
security:
|
||||
password_hashers:
|
||||
# By default, password hashers are resource intensive and take time. This is
|
||||
# important to generate secure password hashes. In tests however, secure hashes
|
||||
# are not important, waste resources and increase test times. The following
|
||||
# reduces the work factor to the lowest possible values.
|
||||
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface:
|
||||
algorithm: auto
|
||||
cost: 4 # Lowest possible value for bcrypt
|
||||
time_cost: 3 # Lowest possible value for argon
|
||||
memory_cost: 10 # Lowest possible value for argon
|
||||
|
|
|
|||
|
|
@ -2,7 +2,13 @@
|
|||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Form\UserSignupType;
|
||||
use App\Form\UserLoginType;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
|
|
@ -17,10 +23,32 @@ class UserController extends AbstractController
|
|||
}
|
||||
|
||||
#[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', [
|
||||
'controller_name' => 'UserController',
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,20 +6,15 @@ use App\Entity\User;
|
|||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||
|
||||
class UserLoginType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('name')
|
||||
->add('fullname')
|
||||
->add('grade')
|
||||
->add('mail')
|
||||
->add('mdp')
|
||||
->add('address')
|
||||
->add('id_resto')
|
||||
;
|
||||
->add('mdp', PasswordType::class);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
|
|
|
|||
|
|
@ -6,20 +6,28 @@ use App\Entity\User;
|
|||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||
|
||||
class UserSignupType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('name')
|
||||
->add('fullname')
|
||||
->add('grade')
|
||||
->add('mail')
|
||||
->add('mdp')
|
||||
->add('address')
|
||||
->add('id_resto')
|
||||
;
|
||||
->add('name', null, [
|
||||
'attr' => ['placeholder' => 'Entrez votre nom de famille']
|
||||
])
|
||||
->add('fullname', null, [
|
||||
'attr' => ['placeholder' => 'Entrez votre prénom']
|
||||
])
|
||||
->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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>McDo : {% block title %}{% endblock %}</title>
|
||||
|
|
|
|||
|
|
@ -7,5 +7,14 @@
|
|||
<div>
|
||||
<h1>Signup !</h1>
|
||||
|
||||
<article>
|
||||
{{ form_start(form) }}
|
||||
{{ form_widget(form) }}
|
||||
<button class="btn">
|
||||
{{ button_label|default('Save') }}
|
||||
</button>
|
||||
{{ form_end(form) }}
|
||||
</article>
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue