src/Controller/GoogleController.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. class GoogleController extends AbstractController
  9. {
  10.     /** * Link to this controller to start the "connect" process * * @Route("/connect/google", name="connect_google") * @param ClientRegistry $clientRegistry * @return \Symfony\Component\HttpFoundation\RedirectResponse */
  11.     public function connectAction(ClientRegistry $clientRegistry)
  12.     {
  13.         return $clientRegistry
  14.         ->getClient('google')
  15.         ->redirect([], [
  16.             'prompt' => 'consent',
  17.         ]);
  18.     }
  19.     /** * Facebook redirects to back here afterward * * @Route("/connect/google/check", name="connect_google_check") * @param Request $request * @return JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse */
  20.     public function connectCheckAction(Request $request)
  21.     {
  22.         if (!$this->getUser()) {
  23.             return new JsonResponse(array('status' => false'message' => "User not found!"));
  24.         } else if($this->getUser()->getEnabled()){
  25.             echo "se cumple esta sentencia de redirecion a defauly";
  26.             if (in_array("ROLE_PATIENT"$this->getUser()->getRoles())) {
  27.                 return $this->redirectToRoute('dashboard_patient');
  28.             }elseif(in_array("ROLE_DOCTOR"$this->getUser()->getRoles())) {
  29.                 return $this->redirectToRoute('dashboard_doctor');
  30.             }elseif(in_array("ROLE_NUTRITIONIST"$this->getUser()->getRoles())) {
  31.                 return $this->redirectToRoute('dashboard_nutritionist');
  32.             }
  33.           
  34.             return $this->redirectToRoute('easyadmin');
  35.         }else if($this->getUser()->getIsVerified()){
  36.             echo "se cumple esta sentencia de redirecion a defauly";
  37.             return $this->redirectToRoute('app_registerPatient');
  38.         }else{           
  39.             return $this->redirectToRoute('app_registerRedirect');
  40.         }
  41.     }
  42. }