|
1 <?php |
|
2 |
|
3 /* |
|
4 * This file is part of the FOSUserBundle package. |
|
5 * |
|
6 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
|
7 * |
|
8 * For the full copyright and license information, please view the LICENSE |
|
9 * file that was distributed with this source code. |
|
10 */ |
|
11 |
|
12 namespace FOS\UserBundle\Controller; |
|
13 |
|
14 use Symfony\Component\DependencyInjection\ContainerAware; |
|
15 use Symfony\Component\Security\Core\SecurityContext; |
|
16 use Symfony\Component\Security\Core\Exception\AuthenticationException; |
|
17 |
|
18 class SecurityController extends ContainerAware |
|
19 { |
|
20 public function loginAction() |
|
21 { |
|
22 $request = $this->container->get('request'); |
|
23 /* @var $request \Symfony\Component\HttpFoundation\Request */ |
|
24 $session = $request->getSession(); |
|
25 /* @var $session \Symfony\Component\HttpFoundation\Session */ |
|
26 |
|
27 // get the error if any (works with forward and redirect -- see below) |
|
28 if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) { |
|
29 $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR); |
|
30 } elseif (null !== $session && $session->has(SecurityContext::AUTHENTICATION_ERROR)) { |
|
31 $error = $session->get(SecurityContext::AUTHENTICATION_ERROR); |
|
32 $session->remove(SecurityContext::AUTHENTICATION_ERROR); |
|
33 } else { |
|
34 $error = ''; |
|
35 } |
|
36 |
|
37 if ($error) { |
|
38 // TODO: this is a potential security risk (see http://trac.symfony-project.org/ticket/9523) |
|
39 $error = $error->getMessage(); |
|
40 } |
|
41 // last username entered by the user |
|
42 $lastUsername = (null === $session) ? '' : $session->get(SecurityContext::LAST_USERNAME); |
|
43 |
|
44 return $this->container->get('templating')->renderResponse('FOSUserBundle:Security:login.html.'.$this->container->getParameter('fos_user.template.engine'), array( |
|
45 'last_username' => $lastUsername, |
|
46 'error' => $error, |
|
47 )); |
|
48 } |
|
49 |
|
50 public function checkAction() |
|
51 { |
|
52 throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.'); |
|
53 } |
|
54 |
|
55 public function logoutAction() |
|
56 { |
|
57 throw new \RuntimeException('You must activate the logout in your security firewall configuration.'); |
|
58 } |
|
59 } |