Handles authentication endpoints for user login and token issuance, leveraging user repository for credential verification.
<?php
namespace App\Controller;
use App\Repository\UserRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\Security\Http\Util\TargetPathTrait;
class SecurityController extends AbstractController
{
use TargetPathTrait;
#[Route('/login', name: 'app_login')]
public function login(
Request $request,
AuthenticationUtils
$authenticationUtils,
UserRepository $userRepository
): Response {
if ($this->getUser()) {
$this->redirectToRoute('app_homepage');
}
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key