Completed
Pull Request — master (#14)
by Jeff
09:20
created

SecurityController::logoutAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
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('easyadmin');
35
        }
36
37
        $error = $authenticationUtils->getLastAuthenticationError();
38
        $lastUsername = $authenticationUtils->getLastUsername();
39
40
        return $this->render('admin/login.html.twig', [
41
            'last_username' => $lastUsername,
42
            'error' => $error,
43
            'csrf_token_intention' => 'authenticate',
44
        ]);
45
    }
46
47
    /**
48
     * @Route("/logout", name="app_logout")
49
     */
50
    public function logoutAction(): Response
51
    {
52
        return $this->redirectToRoute('easyadmin');
53
    }
54
}
55