Completed
Pull Request — master (#91)
by Piotr
03:42
created

SecurityController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 57
c 0
b 0
f 0
wmc 3
lcom 1
cbo 4
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A loginAction() 0 16 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
    /**
39
     * @param EngineInterface $templating
40
     * @param AuthenticationUtils $authenticationUtils
41
     * @param FlashMessages $flashMessages
42
     * @param string $loginActionTemplate
43
     */
44
    public function __construct(
45
        EngineInterface $templating,
46
        AuthenticationUtils $authenticationUtils,
47
        FlashMessages $flashMessages,
48
        $loginActionTemplate
49
    ) {
50
        $this->templating = $templating;
51
        $this->authenticationUtils = $authenticationUtils;
52
        $this->flashMessages = $flashMessages;
53
        $this->loginActionTemplate = $loginActionTemplate;
54
    }
55
56
    public function loginAction()
57
    {
58
        $error = $this->authenticationUtils->getLastAuthenticationError();
59
        if ($error) {
60
            $this->flashMessages->error(
61
                $error->getMessageKey(),
62
                'security',
63
                $error->getMessageData()
64
            );
65
        }
66
67
        return $this->templating->renderResponse(
68
            $this->loginActionTemplate,
69
            ['last_username' => $this->authenticationUtils->getLastUsername()]
70
        );
71
    }
72
}
73