1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
-
-
-
- namespace FOS\UserBundle\Controller;
-
- use Symfony\Component\DependencyInjection\ContainerAware;
- use Symfony\Component\Security\Core\SecurityContext;
-
- class SecurityController extends ContainerAware
- {
- public function loginAction()
- {
- $request = $this->container->get('request');
-
- $session = $request->getSession();
-
-
-
- if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
- $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
- } elseif (null !== $session && $session->has(SecurityContext::AUTHENTICATION_ERROR)) {
- $error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
- $session->remove(SecurityContext::AUTHENTICATION_ERROR);
- } else {
- $error = '';
- }
-
- if ($error) {
-
- $error = $error->getMessage();
- }
-
- $lastUsername = (null === $session) ? '' : $session->get(SecurityContext::LAST_USERNAME);
-
- $csrfToken = $this->container->get('form.csrf_provider')->generateCsrfToken('authenticate');
-
- return $this->renderLogin(array(
- 'last_username' => $lastUsername,
- 'error' => $error,
- 'csrf_token' => $csrfToken,
- ));
- }
-
-
-
- protected function renderLogin(array $data)
- {
- $template = sprintf('FOSUserBundle:Security:login.html.%s', $this->container->getParameter('fos_user.template.engine'));
-
- return $this->container->get('templating')->renderResponse($template, $data);
- }
-
- public function checkAction()
- {
- throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.');
- }
-
- public function logoutAction()
- {
- throw new \RuntimeException('You must activate the logout in your security firewall configuration.');
- }
- }
|