SecurityController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * This file is part of the mailserver-admin package.
6
 * (c) Jeffrey Boehm <https://github.com/jeboehm/mailserver-admin>
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace App\Controller;
12
13
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
14
use Symfony\Component\HttpFoundation\Response;
15
use Symfony\Component\Routing\Annotation\Route;
16
use Symfony\Component\Security\Core\Security;
17
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
18
19
class SecurityController extends AbstractController
20
{
21
    private Security $security;
22
23
    public function __construct(Security $security)
24
    {
25
        $this->security = $security;
26
    }
27
28
    /**
29
     * @Route("/login", name="app_login")
30
     */
31
    public function loginAction(AuthenticationUtils $authenticationUtils): Response
32
    {
33
        if (null !== $this->security->getUser()) {
34
            return $this->redirectToRoute('admin_index');
35
        }
36
37
        $error = $authenticationUtils->getLastAuthenticationError();
38
        $lastUsername = $authenticationUtils->getLastUsername();
39
40
        return $this->render(
41
            'admin/login.html.twig',
42
            [
43
                'last_username' => $lastUsername,
44
                'error' => $error,
45
                'target_path' => $this->generateUrl('admin_index'),
46
                'username_label' => 'Email address',
47
                'page_title' => 'mailserver-admin',
48
                'csrf_token_intention' => 'authenticate',
49
            ]
50
        );
51
    }
52
53
    /**
54
     * @Route("/logout", name="app_logout")
55
     */
56
    public function logoutAction(): Response
57
    {
58
        return $this->redirectToRoute('admin_index');
59
    }
60
}
61