104
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoder;
use Symfony\Component\Security\Core\Security;
class SecurityController extends InitializableController
{
/**
* @return RedirectResponse|Response
* @Config\Route("/login", name = "site_security_login")
*/
public function loginAction()
{
if ($this->authChecker->isGranted(Role::USER)) return $this-
>redirectToRoute('homepage');
$error = null;
if ($this->request->attributes->has(Security::AUTHENTICATION_ERROR))
$error = $this->request->attributes-
>get(Security::AUTHENTICATION_ERROR);
else {
$error = $this->session->get(Security::AUTHENTICATION_ERROR, null);
$this->session->remove(Security::AUTHENTICATION_ERROR);
}
if (!is_null($error)) {
$this->addNotice('error', 'security_login.html.twig', array('notice' =>
'auth_error'));
}
$form = $this->createForm(new LoginFormType(), new User());
$this->navigation = array('active' => 'login');
$this->forms = array(
'login' => $form->createView(),
'last_username' => $this->session->get(Security::LAST_USERNAME, null)
);
return $this->render('AppBundle:Security:login.html.twig');
}
/**
* @throws NotFoundHttpException
* @Config\Route("/login-check", name = "site_security_login_check")
*/
public function loginCheckAction()
{
throw $this->createNotFoundException();
}
/**
* @throws NotFoundHttpException
* @Config\Route("/logout", name = "site_security_logout")
*/
public function logoutAction()
{
throw $this->createNotFoundException();