forked from Sylius/Sylius
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SecurityController.php
96 lines (82 loc) · 2.62 KB
/
SecurityController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Sylius\Bundle\UiBundle\Controller;
use Sylius\Bundle\UiBundle\Form\Type\SecurityLoginType;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
/**
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
final class SecurityController
{
/**
* @var AuthenticationUtils
*/
private $authenticationUtils;
/**
* @var FormFactoryInterface
*/
private $formFactory;
/**
* @var EngineInterface
*/
private $templatingEngine;
/**
* @param AuthenticationUtils $authenticationUtils
* @param FormFactoryInterface $formFactory
* @param EngineInterface $templatingEngine
*/
public function __construct(
AuthenticationUtils $authenticationUtils,
FormFactoryInterface $formFactory,
EngineInterface $templatingEngine
) {
$this->authenticationUtils = $authenticationUtils;
$this->formFactory = $formFactory;
$this->templatingEngine = $templatingEngine;
}
/**
* @param Request $request
*
* @return Response
*/
public function loginAction(Request $request): Response
{
$lastError = $this->authenticationUtils->getLastAuthenticationError();
$lastUsername = $this->authenticationUtils->getLastUsername();
$options = $request->attributes->get('_sylius');
$template = $options['template'] ?? '@SyliusUi/Security/login.html.twig';
$formType = $options['form'] ?? SecurityLoginType::class;
$form = $this->formFactory->createNamed('', $formType);
return $this->templatingEngine->renderResponse($template, [
'form' => $form->createView(),
'last_username' => $lastUsername,
'last_error' => $lastError,
]);
}
/**
* @param Request $request
*/
public function checkAction(Request $request): void
{
throw new \RuntimeException('You must configure the check path to be handled by the firewall.');
}
/**
* @param Request $request
*/
public function logoutAction(Request $request): void
{
throw new \RuntimeException('You must configure the logout path to be handled by the firewall.');
}
}