/**
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
$host = $request->getHost();
$baseHost = $this->baseHost;
$subdomain = str_replace('.' . $baseHost, '', $host);
//Check subDomain
$this->checkOldDomains($subdomain);
//Fix logout bug
$str = $baseHost . "/login";
if ($host != $baseHost && strstr($request->getUri(), $str, true)) {
$event->setResponse(new RedirectResponse($this->router->generate('buddy_system_user_homepage_index')));
}
//Fix dashboard error
if ($this->security_context->getToken() && $this->security_context->isGranted('IS_AUTHENTICATED_REMEMBERED') && $request->get('_route') == 'buddy_system_user_homepage_index') {
$this->checkSectionAccess();
$this->activityManager->setUser($this->security_context);
$this->activityManager->login();
if ($this->security_context->isGranted('ROLE_ADMIN') || $this->security_context->isGranted('ROLE_SUPER_ADMIN')) {
$event->setResponse(new RedirectResponse($this->router->generate('buddy_system_sadmin_homepage')));
} else {
if ($this->security_context->isGranted('ROLE_BUDDYCOORDINATOR')) {
$event->setResponse(new RedirectResponse($this->router->generate('buddy_system_admin_homepage')));
} else {
$event->setResponse(new RedirectResponse($this->router->generate('buddy_system_members_homepage')));
}
}
}
if ($host == $baseHost) {
if ($request->get('_route') != null && $request->get('_route') != "buddy_system_choose" && $request->get('_route') != "buddy_system_front_change_language_ajax") {
$event->setResponse(new RedirectResponse($this->router->generate('buddy_system_choose')));
}
} else {
//Redirection when /en or /fr at the end
$url = $request->getUri();
if (substr($url, -3) == "/fr" || substr($url, -3) == "/en") {
$event->setResponse(new RedirectResponse(substr($url, 0, strlen($url) - 3)));
}
//Add Section to local
if (!$this->sectionManager->getCurrentSection()) {
/** @var Section $section */
$section = $this->em->getRepository('BuddySystemMainBundle:Section')->findOneBy(array('subdomain' => $subdomain));
//Fix error on www
if (!$section && $subdomain == "www") {
header('Location: http://buddysystem.eu');
}
if (!$section) {
throw new NotFoundHttpException(sprintf('Cannot find section for host "%s", subdomain "%s"', $host, $subdomain));
}
if (!array_key_exists('section', $this->twig->getGlobals())) {
$this->twig->addGlobal('section', $section);
}
$this->sectionManager->setCurrentSection($section);
}
}
if ($this->security_context->getToken() && $this->security_context->getToken()->getUser() && $this->sectionManager->getCurrentSection()) {
$this->checkSectionAccess();
}
}