<?php
namespace Boldr\Cms\CmsBundle\Controller;
use Boldr\Cms\CmsBundle\Homepage\HomepageProviderInterface;
use Boldr\Cms\CmsBundle\Admin\LoginPageConfigurationProviderInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\{ Request, Response };
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Composer\InstalledVersions;
class GeneralController extends AbstractController
{
private HomepageProviderInterface $homepageProvider;
/** @param mixed $homepageId */
public function __construct(HomepageProviderInterface $homepageProvider)
{
$this->homepageProvider = $homepageProvider;
}
/**
* @Route("%locale_prefixes.variable%", name="cms_home", defaults={"_locale":""}, requirements={"_locale":"|%supported_locales_route_mask%"})
*/
public function home(Request $request): Response
{
return $this->homepageProvider->handleHomepage($request, $this->getParameter('boldr_cms.homepage_id'));
}
/**
* @Route("/boldr-login", name="cms_login")
*/
public function login(AuthenticationUtils $authenticationUtils, LoginPageConfigurationProviderInterface $loginPageConfiguration): Response
{
if ($this->getUser())
{
return $this->redirectToRoute('cms_admin');
}
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('@BoldrCms/security/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
'loginPageConfiguration' => $loginPageConfiguration
]);
}
/**
* @Route("/boldr-logout", name="cms_logout")
*/
public function logout(): Response
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
/**
* @Route("/boldr-api/boldrcms/info", name="cms_api_info")
*/
public function info(Request $request): Response
{
$infoApiKey = $this->getParameter('boldr_cms.info_api_key');
if ($infoApiKey === null)
{
throw $this->createNotFoundException();
}
if ($request->headers->get('X-BoldrCms-Authorization') !== $infoApiKey)
{
throw new AccessDeniedHttpException;
}
$packages = [];
foreach (InstalledVersions::getAllRawData()[0]['versions'] as $packageName => $data)
{
if (!isset($data['version']) || $packageName === '__root__')
{
continue;
}
$packages[$packageName] = $data['pretty_version'];
}
return $this->json([
'version' => 1,
'packages' => $packages
]);
}
}