<?php
namespace Hona\AuthBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Hona\AuthBundle\Library\Utils;
class HomeController extends Controller
{
/**
* @Route("/", name="home")
* @param $request
*/
public function indexAction(Request $request)
{
if(empty($request->get('redirect_uri'))){
$admin_domain = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://".$this->getParameter('admin_domain');
$request->request->set('redirect_uri', $admin_domain);
}
if($this->get('session')->has('user_id')){
$parseUrl = parse_url($request->get('redirect_uri'));
if(strpos($parseUrl["host"], $this->container->getParameter('parent_domain')) !== false){
$accessToken = Utils::createAccessToken($this->getDoctrine(), $this->get('session')->get('user_id'));
setcookie("presence", Utils::doubleEncrypt($accessToken->getToken()), time() + Utils::getParameter("token_expires_in"), "/", ".".$this->container->getParameter('parent_domain'));
}
return $this->redirect($request->get('redirect_uri'));
}else{
return $this->render('@HonaAuth/login.html.twig', array(
"onlyMetas" => true,
"redirect_uri" => $request->get('redirect_uri')
));
}
}
}