|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
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 Sylius\Bundle\UiBundle\Controller; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
15
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; |
|
16
|
|
|
use Symfony\Component\Form\FormFactoryInterface; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
18
|
|
|
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
final class SecurityController |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var AuthenticationUtils |
|
27
|
|
|
*/ |
|
28
|
|
|
private $authenticationUtils; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var FormFactoryInterface |
|
32
|
|
|
*/ |
|
33
|
|
|
private $formFactory; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var EngineInterface |
|
37
|
|
|
*/ |
|
38
|
|
|
private $templatingEngine; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param AuthenticationUtils $authenticationUtils |
|
42
|
|
|
* @param FormFactoryInterface $formFactory |
|
43
|
|
|
* @param EngineInterface $templatingEngine |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct(AuthenticationUtils $authenticationUtils, FormFactoryInterface $formFactory, EngineInterface $templatingEngine) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->authenticationUtils = $authenticationUtils; |
|
48
|
|
|
$this->formFactory = $formFactory; |
|
49
|
|
|
$this->templatingEngine = $templatingEngine; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param Request $request |
|
54
|
|
|
*/ |
|
55
|
|
|
public function loginAction(Request $request) |
|
56
|
|
|
{ |
|
57
|
|
|
$lastError = $this->authenticationUtils->getLastAuthenticationError(); |
|
58
|
|
|
$lastUsername = $this->authenticationUtils->getLastUsername(); |
|
59
|
|
|
|
|
60
|
|
|
$template = $request->attributes->get('_sylius[template]', 'SyliusUiBundle:Security:login.html.twig', true); |
|
61
|
|
|
$formType = $request->attributes->get('_sylius[form]', 'sylius_security_login', true); |
|
62
|
|
|
$form = $this->formFactory->createNamed('', $formType); |
|
63
|
|
|
|
|
64
|
|
|
return $this->templatingEngine->renderResponse($template, array( |
|
65
|
|
|
'form' => $form->createView(), |
|
66
|
|
|
'last_username' => $lastUsername, |
|
67
|
|
|
'last_error' => $lastError, |
|
68
|
|
|
)); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param Request $request |
|
73
|
|
|
*/ |
|
74
|
|
|
public function checkAction(Request $request) |
|
75
|
|
|
{ |
|
76
|
|
|
throw new \RuntimeException('You must configure the check path to be handled by the firewall.'); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param Request $request |
|
81
|
|
|
*/ |
|
82
|
|
|
public function logoutAction(Request $request) |
|
83
|
|
|
{ |
|
84
|
|
|
throw new \RuntimeException('You must configure the logout path to be handled by the firewall.'); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|