From e663dd23cb4c1685042e106474c6fab385ba7eea Mon Sep 17 00:00:00 2001 From: Florian Eisenmenger Date: Tue, 19 Dec 2023 16:03:46 +0100 Subject: [PATCH] security --- config/packages/security.yaml | 2 +- src/Controller/SecurityController.php | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/config/packages/security.yaml b/config/packages/security.yaml index dcb8fc1..3677c9f 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -18,7 +18,7 @@ security: provider: app_user_provider json_login: check_path: app_login - username_path: email + username_path: username password_path: password # activate different ways to authenticate diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php index c3d0934..b3ea2d9 100644 --- a/src/Controller/SecurityController.php +++ b/src/Controller/SecurityController.php @@ -3,7 +3,9 @@ namespace App\Controller; use ApiPlatform\Api\IriConverterInterface; +use App\Entity\User; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Security\Http\Attribute\CurrentUser; @@ -20,9 +22,17 @@ class SecurityController extends AbstractController ], 401); } - return new Response(null, 204, [ - 'Location' => $iriConverter->getIriFromResource($user), + /** @var User $user */ + return new JsonResponse([ + 'id' => $user->getId(), + 'username' => $user->getFirstName() . '_' . $user->getLastName(), + 'firstName' => $user->getFirstName(), + 'lastName' => $user->getLastName() ]); + +// return new Response(null, 204, [ +// 'Location' => $iriConverter->getIriFromResource($user), +// ]); } #[Route('/logout', name: 'app_logout')]