src/Controller/GoogleAuthenticator/GoogleController.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Controller\GoogleAuthenticator;
  3. use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\{JsonResponseRequest};
  6. use Symfony\Component\Routing\Annotation\Route;
  7. class GoogleController extends AbstractController
  8. {
  9.     /**
  10.      * Link to this controller to start the "connect" process
  11.      * 
  12.      * @Route("/connect/google", name="connect_google")
  13.      * @param ClientRegistry $clientRegistry
  14.      * @return \Symfony\Component\HttpFoundation\RedirectResponse 
  15.      */
  16.     public function connectAction(ClientRegistry $clientRegistry)
  17.     {
  18.         return $clientRegistry
  19.             ->getClient('google')
  20.             ->redirect();
  21.     }
  22.     /**
  23.      * redirects to back here afterward  
  24.      * 
  25.      * @Route("/connect/google/check", name="connect_google_check")
  26.      * @param Request $request
  27.      * @return JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse
  28.      */
  29.     public function connectCheckAction(Request $request)
  30.     {
  31.         if(!$this->getUser()){
  32.             return new JsonResponse(['status'=>false,'message'=>"User not found!"]);
  33.         }else{
  34.             return $this->redirectToRoute('home');
  35.         }
  36.     }
  37. }