From a15e35e2afce655b71767adb6a8163a37780b311 Mon Sep 17 00:00:00 2001 From: Roshan Budhathoki Date: Tue, 16 Aug 2016 18:01:49 +0545 Subject: [PATCH] Fix not redirecting to URL Updated RedirectCallBack to fix not redirecting to a url problem. It was having problem here on two of these functions private function routeExists($route) { try { $this->router->assemble(array(), array('name' => $route)); } catch (Exception\RuntimeException $e) { return false; } return true; } protected function getRedirect($currentRoute, $redirect = false) { $useRedirect = $this->options->getUseRedirectParameterIfPresent(); $routeExists = ($redirect && $this->routeExists($redirect)); if (!$useRedirect || !$routeExists) { $redirect = false; } switch ($currentRoute) { case 'zfcuser/register': case 'zfcuser/login': case 'zfcuser/authenticate': $route = ($redirect) ?: $this->options->getLoginRedirectRoute(); return $this->router->assemble(array(), array('name' => $route)); break; case 'zfcuser/logout': $route = ($redirect) ?: $this->options->getLogoutRedirectRoute(); return $this->router->assemble(array(), array('name' => $route)); break; default: return $this->router->assemble(array(), array('name' => 'zfcuser')); } } --- src/ZfcUser/Controller/RedirectCallback.php | 33 ++++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/ZfcUser/Controller/RedirectCallback.php b/src/ZfcUser/Controller/RedirectCallback.php index 273fea85..7255d939 100644 --- a/src/ZfcUser/Controller/RedirectCallback.php +++ b/src/ZfcUser/Controller/RedirectCallback.php @@ -74,14 +74,34 @@ private function getRedirectRouteFromRequest() * @param $route * @return bool */ - private function routeExists($route) + private function routeExists($route) { + // first check if such rout/name exists + // will throw exception if does not exist + $namedRouteMatch=0; + $urlRouteMatch=0; + try{ + $this->router->assemble(array(), array('name' => $route)); + }catch (Exception\RuntimeException $e) { + // didnt' match with any route name + $match=0; + } + + // now try to match url with routes try { - $this->router->assemble(array(), array('name' => $route)); + $request=$this->application->getRequest(); + $request->setUri($route); + $matchedRoute = $this->router->match($request); + if($matchedRoute){ + $urlRouteMatch=1; + } } catch (Exception\RuntimeException $e) { - return false; + $urlRouteMatch=0; } + // check if anyof them matched + if($namedRouteMatch || $urlRouteMatch){ return true; + } } /** @@ -104,7 +124,12 @@ protected function getRedirect($currentRoute, $redirect = false) case 'zfcuser/register': case 'zfcuser/login': case 'zfcuser/authenticate': - $route = ($redirect) ?: $this->options->getLoginRedirectRoute(); + // if redirect is there and matches a route just return it + if($redirect){ + return $redirect; + } + // since its route name asseble and return string url + $route =$this->options->getLoginRedirectRoute(); return $this->router->assemble(array(), array('name' => $route)); break; case 'zfcuser/logout':