Linux SRV-16 6.18.44-paas #1 SMP PREEMPT_DYNAMIC Thu Aug 13 10:08:12 UTC 2026 x86_64
/
srv
/
data
/
trash
/
vhost_www.rec-app.app_1716798588
/
htdocs
/
src
/
Controller
/
Api
/
/srv/data/trash/vhost_www.rec-app.app_1716798588/htdocs/src/Controller/Api/LoginController.php
<?php namespace App\Controller\Api; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; use Symfony\Component\Security\Core\User\UserProviderInterface; use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface; class LoginController extends AbstractController { /** * @Route("/api/login", name="api_login", methods={"POST"}) */ public function login(Request $request, UserPasswordEncoderInterface $encoder, UserProviderInterface $userProvider, JWTTokenManagerInterface $jwtManager): JsonResponse { $data = json_decode($request->getContent(), true); $email = $data['email']; $password = $data['password']; $user = $userProvider->loadUserByUsername($email); if (!$user || !$encoder->isPasswordValid($user, $password)) { return new JsonResponse(['message' => 'Invalid credentials'], JsonResponse::HTTP_UNAUTHORIZED); } $token = $jwtManager->create($user); return new JsonResponse(['token' => $token]); } }