<?php
namespace App\Controller;
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class GoogleController extends AbstractController
{
/** * Link to this controller to start the "connect" process * * @Route("/connect/google", name="connect_google") * @param ClientRegistry $clientRegistry * @return \Symfony\Component\HttpFoundation\RedirectResponse */
public function connectAction(ClientRegistry $clientRegistry)
{
return $clientRegistry
->getClient('google')
->redirect([], [
'prompt' => 'consent',
]);
}
/** * Facebook redirects to back here afterward * * @Route("/connect/google/check", name="connect_google_check") * @param Request $request * @return JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse */
public function connectCheckAction(Request $request)
{
if (!$this->getUser()) {
return new JsonResponse(array('status' => false, 'message' => "User not found!"));
} else if($this->getUser()->getEnabled()){
echo "se cumple esta sentencia de redirecion a defauly";
if (in_array("ROLE_PATIENT", $this->getUser()->getRoles())) {
return $this->redirectToRoute('dashboard_patient');
}elseif(in_array("ROLE_DOCTOR", $this->getUser()->getRoles())) {
return $this->redirectToRoute('dashboard_doctor');
}elseif(in_array("ROLE_NUTRITIONIST", $this->getUser()->getRoles())) {
return $this->redirectToRoute('dashboard_nutritionist');
}
return $this->redirectToRoute('easyadmin');
}else if($this->getUser()->getIsVerified()){
echo "se cumple esta sentencia de redirecion a defauly";
return $this->redirectToRoute('app_registerPatient');
}else{
return $this->redirectToRoute('app_registerRedirect');
}
}
}