Completed
Push — master ( d67956...a656c9 )
by Piotr
11s
created

SecurityController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A loginAction() 0 14 2
1
<?php
2
3
/**
4
 * (c) FSi sp. z o.o. <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace FSi\Bundle\AdminSecurityBundle\Controller;
11
12
use FSi\Bundle\AdminBundle\Message\FlashMessages;
13
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
14
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
15
16
class SecurityController
17
{
18
    /**
19
     * @var EngineInterface
20
     */
21
    private $templating;
22
23
    /**
24
     * @var AuthenticationUtils
25
     */
26
    private $authenticationUtils;
27
28
    /**
29
     * @var FlashMessages
30
     */
31
    private $flashMessages;
32
33
    /**
34
     * @var string
35
     */
36
    private $loginActionTemplate;
37
38
    public function __construct(
39
        EngineInterface $templating,
40
        AuthenticationUtils $authenticationUtils,
41
        FlashMessages $flashMessages,
42
        string $loginActionTemplate
43
    ) {
44
        $this->templating = $templating;
45
        $this->authenticationUtils = $authenticationUtils;
46
        $this->flashMessages = $flashMessages;
47
        $this->loginActionTemplate = $loginActionTemplate;
48
    }
49
50
    public function loginAction()
51
    {
52
        $error = $this->authenticationUtils->getLastAuthenticationError();
53
        if ($error) {
54
            $this->flashMessages->error(
55
                $error->getMessageKey(),
56
                $error->getMessageData(),
57
                'security'
58
            );
59
        }
60
61
        return $this->templating->renderResponse(
62
            $this->loginActionTemplate,
63
            ['last_username' => $this->authenticationUtils->getLastUsername()]
64
        );
65
    }
66
}
67