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':