Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| SecurityController | |
100.00% |
17 / 17 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
1 / 1 |
| loginAction | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
2 | |||
| loginCheckAction | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| logoutAction | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| adminDashboardAction | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Controller; |
| 4 | |
| 5 | use App\Entity\Task; |
| 6 | use App\Entity\User; |
| 7 | use Doctrine\ORM\EntityManagerInterface; |
| 8 | use Symfony\Component\HttpFoundation\Response; |
| 9 | use Symfony\Component\Routing\Annotation\Route; |
| 10 | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
| 11 | use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; |
| 12 | |
| 13 | class SecurityController extends AbstractController |
| 14 | { |
| 15 | /** |
| 16 | * Handles the login functionality. |
| 17 | * |
| 18 | * @param AuthenticationUtils $authenticationUtils The authentication utils service. |
| 19 | * @return Response The response object. |
| 20 | * |
| 21 | */ |
| 22 | #[Route('/login', name: 'app_login', methods: ['GET', 'POST'])] |
| 23 | public function loginAction(AuthenticationUtils $authenticationUtils): Response |
| 24 | { |
| 25 | // Get the login error if there is one |
| 26 | $error = $authenticationUtils->getLastAuthenticationError(); |
| 27 | if ($error) { |
| 28 | $this->addFlash('danger', $error->getMessageKey()); |
| 29 | } |
| 30 | |
| 31 | // Get the last username entered by the user |
| 32 | $lastUsername = $authenticationUtils->getLastUsername(); |
| 33 | |
| 34 | return $this->render('security/login.html.twig', [ |
| 35 | 'controller_name' => 'SecurityController', |
| 36 | 'last_username' => $lastUsername, |
| 37 | 'error' => $error, |
| 38 | ]); |
| 39 | } |
| 40 | |
| 41 | #[Route('/login_check', name: 'app_login_check', methods: ['GET'])] |
| 42 | public function loginCheckAction(): void |
| 43 | { |
| 44 | // This code is never executed |
| 45 | } |
| 46 | |
| 47 | |
| 48 | /** |
| 49 | * @codeCoverageIgnore |
| 50 | */ |
| 51 | #[Route('/logout', name: 'app_logout', methods: ['GET'])] |
| 52 | public function logoutAction(): void |
| 53 | { |
| 54 | // This code is never executed |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Renders the admin dashboard page. |
| 59 | * |
| 60 | * @param EntityManagerInterface $emi The entity manager interface. |
| 61 | * @return Response The response object. |
| 62 | */ |
| 63 | #[Route('/admin', name: 'app_admin', methods: ['GET'])] |
| 64 | public function adminDashboardAction(EntityManagerInterface $emi): Response |
| 65 | { |
| 66 | $users = $emi->getRepository(User::class)->findAll(); |
| 67 | $tasks = $emi->getRepository(Task::class)->findAll(); |
| 68 | |
| 69 | return $this->render('security/admin.html.twig', [ |
| 70 | 'controller_name' => 'SecurityController', |
| 71 | 'users' => $users, |
| 72 | 'tasks' => $tasks, |
| 73 | ]); |
| 74 | } |
| 75 | } |