<?php
namespace Kobizo\Bundle\CoreBundle\Controller;
use Kobizo\Component\Attributes\DefaultRolesAttribute;
use Kobizo\Component\Configuration\Google\GoogleCaptchaConfig;
use Kobizo\Component\Configuration\Google\GoogleCaptchaPublicKeyConfig;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class FeSecurityController extends KobizoFeAbstractController
{
/**
* @Route("/login", name="app_login")
*/
public function login(
AuthenticationUtils $authenticationUtils,
GoogleCaptchaConfig $googleCaptchaConfig,
GoogleCaptchaPublicKeyConfig $googleCaptchaPublicKeyConfig
): Response {
if ($this->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_FULLY)
&& $this->getUser()
&& $this->isGranted(DefaultRolesAttribute::CLIENT)
) {
return $this->redirectToRoute('customer_account', [], 302, false);
}
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
$googleCaptchaEnable = $googleCaptchaConfig->isGoogleCaptchaEnabled();
return $this->render('@KobizoCore/frontend/login.twig', [
'last_username' => $lastUsername,
'error' => $error,
'isGoogleCaptchaEnabled' => $googleCaptchaEnable,
'captcha_public_key' => $googleCaptchaEnable ? $googleCaptchaPublicKeyConfig->getValue() : "",
]);
}
/**
* @Route("/logout", name="app_logout")
*/
public function logout()
{
return $this->redirectToRoute('home');
}
}