diff --git a/application/src/Controller/SecurityController.php b/application/src/Controller/SecurityController.php index b106448..fc36d14 100644 --- a/application/src/Controller/SecurityController.php +++ b/application/src/Controller/SecurityController.php @@ -22,7 +22,10 @@ class SecurityController extends AbstractController $error = $authenticationUtils->getLastAuthenticationError(); if ($error) { $this->addFlash('danger', $error->getMessage()); + }else{ + $this->addFlash('success', "User loged in."); } + $this->addFlash('info', $authenticationUtils->getLastUsername()); return $this->render("user/login.html.twig",[ 'last_username'=>$authenticationUtils->getLastUsername(), ]); diff --git a/application/src/Controller/UserController.php b/application/src/Controller/UserController.php index 1c87fe2..f561877 100644 --- a/application/src/Controller/UserController.php +++ b/application/src/Controller/UserController.php @@ -10,6 +10,7 @@ use Symfony\Component\Form\Extension\Core\Type\PasswordType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; /** * @@ -32,7 +33,7 @@ class UserController extends AbstractController implements UserControllerInterfa * * @Route("/user/register", name="user_register") */ - public function register(Request $request): Response + public function register(Request $request,UserPasswordEncoderInterface $encoder): Response { $user = new User(); $form = $this->createFormBuilder($user) @@ -44,9 +45,11 @@ class UserController extends AbstractController implements UserControllerInterfa ->getForm(); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $task = $form->getData(); + $user = $form->getData(); + $encoded = $encoder->encodePassword($user, $request->get('password')); + $user->setPassword($encoded); $entityManager = $this->getDoctrine()->getManager(); - $entityManager->persist($task); + $entityManager->persist($user); try { $entityManager->flush(); $this->addFlash('success', 'User created!'); diff --git a/application/src/Controller/UserControllerInterface.php b/application/src/Controller/UserControllerInterface.php index 2b96299..8393a4f 100644 --- a/application/src/Controller/UserControllerInterface.php +++ b/application/src/Controller/UserControllerInterface.php @@ -14,5 +14,5 @@ interface UserControllerInterface { public function logout():Response; - public function register(Request $request):Response; + #public function register(Request $request):Response; } diff --git a/application/src/Entity/Attribut/UsernameAttribut.php b/application/src/Entity/Attribut/UsernameAttribut.php index b3c3b23..90c60ea 100644 --- a/application/src/Entity/Attribut/UsernameAttribut.php +++ b/application/src/Entity/Attribut/UsernameAttribut.php @@ -19,7 +19,7 @@ trait UsernameAttribut{ } public function setUsername(string $username):void{ - $this->username = $username; + $this->username = \trim($username); } } diff --git a/application/tests/unit/Controller/UserControllerTest.php b/application/tests/unit/Controller/UserControllerTest.php index 80b5ecc..e9a29cb 100644 --- a/application/tests/unit/Controller/UserControllerTest.php +++ b/application/tests/unit/Controller/UserControllerTest.php @@ -32,7 +32,7 @@ class UserControllerTest extends WebTestCase public function testLogin(): void { $client = static::createClient(); - $client->request('GET', '/user/login'); + $client->request('GET', '/login'); $this->assertEquals(200, $client->getResponse()->getStatusCode()); } diff --git a/application/tests/unit/Entity/UserTest.php b/application/tests/unit/Entity/UserTest.php index 5af36e4..167c2e4 100644 --- a/application/tests/unit/Entity/UserTest.php +++ b/application/tests/unit/Entity/UserTest.php @@ -24,7 +24,7 @@ class UserTest extends TestCase public function setUp():void{ $this->user = new User(); $this->user->setPassword(self::PASSWORD); - $this->user->setUsername(self::USERNAME); + $this->user->setUsername(' '.self::USERNAME.' '); } public function testUsername():void{