<?php
declare(strict_types=1);
namespace App\Controller\Security;
use App\Form\Security\LoginFormType;
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
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;
class SecurityController extends AbstractController
{
/**
* @Route("/login", name="security_login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
$form = $this->createForm(LoginFormType::class, [
'username' => $authenticationUtils->getLastUsername(),
]);
return $this->render('Security/login.html.twig', [
'form' => $form->createView(),
'last_username' => $authenticationUtils->getLastUsername(),
'error' => $authenticationUtils->getLastAuthenticationError(),
]);
}
/**
* @Route("/connect/social", name="security_social_login")
*/
public function connect(ClientRegistry $clientRegistry, Request $request)
{
$client = $clientRegistry->getClient($request->query->get('client'));
if ('facebook' === $request->query->get('client')) {
return $client->redirect(['public_profile', 'email'], []);
}
return $client->redirect(['email'], []);
}
/**
* @Route("/logout", name="security_logout")
*/
public function logout(): void
{
}
}