33namespace App \Controller ;
44
55use Symfony \Bundle \FrameworkBundle \Controller \Controller ;
6+ use Symfony \Component \HttpFoundation \Cookie ;
67use Symfony \Component \HttpFoundation \JsonResponse ;
78use Symfony \Component \Routing \Annotation \Route ;
8- use FOS \RestBundle \Controller \Annotations as Rest ;
99
1010final class ApiSecurityControllerextends Controller
1111{
@@ -15,7 +15,12 @@ final class ApiSecurityController extends Controller
1515 */
1616public function loginAction ():JsonResponse
1717 {
18- return new JsonResponse ('authenticated! ' );
18+ $ securityCookie =new Cookie ('authenticated ' ,true ,\time () +\intval (\ini_get ('session.gc_maxlifetime ' )),'/ ' ,null ,false ,false );
19+
20+ $ response =new JsonResponse ('authenticated! ' );
21+ $ response ->headers ->setCookie ($ securityCookie );
22+
23+ return $ response ;
1924 }
2025
2126/**
@@ -26,13 +31,4 @@ public function logoutAction()
2631 {
2732throw new \Exception ('This should not be reached! ' );
2833 }
29-
30- /**
31- * @Rest\Get("/api/security/is-authenticated", name="isAuthenticated")
32- * @return JsonResponse
33- */
34- public function isAuthenticatedAction ():JsonResponse
35- {
36- return $ this ->isGranted ('IS_AUTHENTICATED_FULLY ' ) ?new JsonResponse ('authenticated! ' ) :new JsonResponse ('not authenticated! ' ,401 );
37- }
3834}