src/Controller/AccountController.php line 51

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * @copyright Copyright ©️ 2020-2021 seidemann: solutions GmbH <info@seidemann.com> - All Rights Reserved.
  5.  *
  6.  *     Unauthorized copying and/or distribution of this file, via any medium, is strictly prohibited.
  7.  *
  8.  *     Proprietary and confidential.
  9.  */
  10. namespace Seidemann\Hanagud\Controller;
  11. use Exception;
  12. use Seidemann\Hanagud\Entity\HanagudUser;
  13. use Seidemann\Hanagud\Http\ApiResponse;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. use Symfony\Component\Security\Core\User\UserInterface;
  18. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  19. class AccountController extends AbstractController
  20. {
  21.     #[Route(path'/ping'name'ping'methods: ['GET''POST'])]
  22.     public function ping(): Response
  23.     {
  24.         $user $this->getUser();
  25.         $response = [
  26.             'isLoggedIn' => $this->isGranted('ROLE_USER'),
  27.         ];
  28.         if ($user instanceof UserInterface) {
  29.             $userJson = ['id' => $user->getUserIdentifier()];
  30.             if ($user instanceof HanagudUser) {
  31.                 $userJson['articleNumber'] = $user->getArticleNumber();
  32.                 $userJson['userId'] = $user->getId();
  33.                 $userJson['UserGroup'] = $user->getUserGroup();
  34.                 
  35.             }
  36.             $response['user'] = $userJson;
  37.         }
  38.         return new ApiResponse($response);
  39.     }
  40.     #[Route(path'/login'name'login'methods: ['GET''POST'])]
  41.     public function showLoginForm(AuthenticationUtils $authenticationUtils): Response
  42.     {
  43.         // get the login error if there is one
  44.         $error $authenticationUtils->getLastAuthenticationError();
  45.         // last username entered by the user
  46.         $lastUsername $authenticationUtils->getLastUsername();
  47.         return $this->render('login/index.html.twig', [
  48.             'user' => $this->getUser(),
  49.             'is_logged_in' => $this->isGranted('ROLE_USER'),
  50.             'last_username' => $lastUsername,
  51.             'error' => $error,
  52.         ]);
  53.     }
  54.     #[Route(path'/logout'name'logout'methods: ['GET'])]
  55.     public function logout()
  56.     {
  57.         // controller can be blank: it will never be executed!
  58.         throw new Exception('Don\'t forget to activate logout in security.yaml');
  59.     }
  60. }