<?php
namespace Kzl\FrameworkBundle\Controller;
use Kzl\FrameworkBundle\Common\KzlFrameworkStatic;
use Kzl\FrameworkBundle\Entity\Tenant;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
/**
* @todo ichikawa ログイン前のテナントCD取得方法見直し(OnRequestListener内で行いたい)
*/
class UserController extends AbstractController
{
public function login(AuthenticationUtils $authenticationUtils)
{
if ($this->getUser()) {
$tenantManager = KzlFrameworkStatic::getTenantManager();
return $this->redirectToRoute('app_top', ['subfolder' => $tenantManager->getSubfolder()]);
}
$em = $this->getDoctrine()->getManager();
$url = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$urlArray = explode('/', $url);
$subfolder = $urlArray[1];
$tenantCd = $em->getRepository(Tenant::class)
->getActiveTenantCd($subfolder);
$session = KzlFrameworkStatic::getSession();
$session->set('tenant_fillter_tenant_cd', $tenantCd);
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('user/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
]);
}
public function logout(): void
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}