SecurityController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A loginAction() 0 18 2
A logoutAction() 0 3 1
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