/**
  * {@inheritDoc}
  */
 public function switchInstance(InstanceInterface $instance)
 {
     $container = $this->getContainer();
     $container->offsetSet('instance', $instance->getId());
     $url = $this->router->assemble($this->routeMatch->getParams(), ['name' => $this->routeMatch->getMatchedRouteName()]);
     $this->redirect($url);
 }
 /**
  * @param \Zend\Mvc\Router\RouteInterface $oRouter
  * @return \BoilerAppDisplay\View\Helper\JsControllerHelper
  */
 public function setRouter(\Zend\Mvc\Router\RouteInterface $oRouter)
 {
     $this->router = $oRouter;
     if ($this->router instanceof \Zend\Mvc\Router\RouteStackInterface) {
         $this->setRoutes($this->router->getRoutes());
     }
     return $this;
 }
 /**
  * {@inheritDoc}
  */
 public function switchInstance(InstanceInterface $instance)
 {
     if (!array_key_exists('HTTP_HOST', (array) $_SERVER)) {
         throw new Exception\RuntimeException(sprintf('Host not set.'));
     }
     $url = $this->router->assemble($this->routeMatch->getParams(), ['name' => $this->routeMatch->getMatchedRouteName()]);
     $hostNames = explode('.', $_SERVER['HTTP_HOST']);
     $tld = $hostNames[count($hostNames) - 2] . "." . $hostNames[count($hostNames) - 1];
     $url = 'http://' . $instance->getSubdomain() . '.' . $tld . $url;
     $this->redirect($url);
 }
 /**
  * Returns the url to redirect to based on current route.
  * If $redirect is set and the option to use redirect is set to true, it
  * will return the $redirect url.
  *
  * @param string $currentRoute        	
  * @param bool $redirect        	
  * @return mixed
  */
 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':
             if ($redirect && ($match = $this->routeExists($redirect)) == true) {
                 $route = $match->getMatchedRouteName();
                 return $this->router->assemble(array(), array('name' => $route));
             } else {
                 $route = $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'));
     }
 }
 /**
  * Returns the url to redirect to based on current route.
  * If $redirect is set and the option to use redirect is set to true, it will return the $redirect url.
  *
  * @param  string $currentRoute
  * @param  bool   $redirect
  * @return mixed
  */
 private function getRedirect($currentRoute, $redirect = false)
 {
     $useRedirect = $this->options->getUseRedirectParameterIfPresent();
     $routeExists = $redirect && $this->routeExists($redirect);
     if (!$useRedirect || !$routeExists) {
         $redirect = false;
     }
     switch ($currentRoute) {
         case 'zfcuser/login':
         case 'scn-social-auth-user/login':
         case 'scn-social-auth-user/register':
         case 'scn-social-auth-user/authenticate/provider':
         case 'scn-social-auth-user/add-provider/provider':
             $route = $redirect ?: $this->options->getLoginRedirectRoute();
             return $this->router->assemble(array(), array('name' => $route));
             break;
         case 'zfcuser/logout':
         case 'scn-social-auth-user/logout':
             $route = $redirect ?: $this->options->getLogoutRedirectRoute();
             return $this->router->assemble(array(), array('name' => $route));
             break;
         default:
             return $this->router->assemble(array(), array('name' => 'zfcuser'));
     }
 }
Exemple #6
0
 public function testFallbackToAjaxWhenNoClientsideValidatorAvailable()
 {
     $form = $this->createForm('test');
     $this->routerMock->shouldReceive('assemble')->andReturn('/the/uri/to/ajax');
     $inputFilter = new InputFilter();
     $inputFilter->add(array('name' => 'name', 'validators' => array(array('name' => 'isbn'))));
     $form->setInputFilter($inputFilter);
     $this->renderer->preRenderForm('test', $this->view);
     $matches = $this->getMatchesFromInlineScript();
     $rules = $matches['rules'];
     $this->assertEquals('/the/uri/to/ajax', $rules['name']['remote']['url']);
     $this->assertEquals('POST', $rules['name']['remote']['type']);
 }
 public function testGetRedirectWithOptionOnRedirectDoesntExists()
 {
     $route = 'zfcuser/login';
     $redirect = 'doesntExists';
     $expectedResult = '/user/login';
     $this->moduleOptions->expects($this->once())->method('getUseRedirectParameterIfPresent')->will($this->returnValue(true));
     $this->router->expects($this->at(0))->method('assemble')->with(array(), array('name' => $redirect))->will($this->throwException(new \Zend\Mvc\Router\Exception\RuntimeException()));
     $this->router->expects($this->at(1))->method('assemble')->with(array(), array('name' => $route))->will($this->returnValue($expectedResult));
     $this->moduleOptions->expects($this->once())->method('getLoginRedirectRoute')->will($this->returnValue($route));
     $method = new \ReflectionMethod('ZfcUser\\Controller\\RedirectCallback', 'getRedirect');
     $method->setAccessible(true);
     $result = $method->invoke($this->redirectCallback, $route, $redirect);
     $this->assertSame($expectedResult, $result);
 }
Exemple #8
0
 /**
  * @return string|null
  */
 public function resolve()
 {
     if (!$this->request instanceof HttpRequest) {
         return;
     }
     $routeMatch = $this->router->match($this->request);
     if (!$routeMatch) {
         return;
     }
     $matchedRouteName = $routeMatch->getMatchedRouteName();
     foreach ($this->config['wizards'] as $name => $options) {
         if (empty($options['route'])) {
             continue;
         }
         if (is_string($options['route'])) {
             $options['route'] = [$options['route']];
         }
         if (!in_array($matchedRouteName, $options['route'])) {
             continue;
         }
         return $name;
     }
 }
 /**
  * Returns the url to redirect to based on current url.
  * If $redirect is set and the option to use redirect is set to true, it will return the $redirect url
  * after verifying that the url is in the whitelist.
  *
  * @param string $currentRoute
  * @param bool $redirect
  * @return mixed
  */
 private function getRedirect($currentRoute, $redirect = false)
 {
     $useRedirect = $this->zfcUserOptions->getUseRedirectParameterIfPresent();
     $urlAllowed = $redirect && $this->urlWhitelisted($redirect);
     if ($useRedirect && $urlAllowed) {
         return $redirect;
     }
     switch ($currentRoute) {
         case 'zfcuser/register':
         case 'zfcuser/login':
             $route = $this->zfcUserOptions->getLoginRedirectRoute();
             return $this->router->assemble(array(), array('name' => $route));
             break;
         case 'zfcuser/logout':
             $route = $this->zfcUserOptions->getLogoutRedirectRoute();
             return $this->router->assemble(array(), array('name' => $route));
             break;
         default:
             return $this->router->assemble(array(), array('name' => 'zfcuser'));
     }
 }
 /**
  * {@inheritDoc}
  */
 public function toDocument($object)
 {
     if (!$object instanceof EntityInterface) {
         throw new InvalidArgumentException(sprintf('Expected TaxonomyTermInterface but got %s', is_object($object) ? get_class($object) : gettype($object)));
     }
     $normalized = $this->normalizer->normalize($object);
     $id = $object->getId();
     $instance = $object->getInstance()->getId();
     $title = $normalized->getTitle();
     $content = $normalized->getContent();
     $keywords = $normalized->getMetadata()->getKeywords();
     $type = $object->getType()->getName();
     $link = $this->router->assemble($normalized->getRouteParams(), ['name' => $normalized->getRouteName()]);
     try {
         $content = $this->renderService->render($content);
     } catch (RuntimeException $e) {
         // Could not render -> nothing to do.
     }
     $content = $this->stripTags->filter($content);
     return new Document($id, $title, $content, $type, $link, $keywords, $instance);
 }
 /**
  * @param $currentRoute
  * @param bool|false $redirect
  * @return mixed
  */
 protected function getRedirect($currentRoute, $redirect = false)
 {
     $useRedirect = $this->options->isUseRedirectParameterIfPresent();
     $routeExists = $redirect && $this->routeExists($redirect);
     if (!$useRedirect || !$routeExists) {
         $redirect = false;
     }
     switch ($currentRoute) {
         case 'mfcc-admin-user/register':
         case 'mfcc-admin-user/login':
         case 'mfcc-admin-user/authenticate':
             $route = $redirect ?: $this->options->getLoginRedirectRoute();
             return $this->router->assemble([], ['name' => $route]);
             break;
         case 'mfcc-admin-user/logout':
             $route = $redirect ?: $this->options->getLogoutRedirectRoute();
             return $this->router->assemble([], ['name' => $route]);
             break;
         default:
             return $this->router->assemble([], ['name' => 'user']);
     }
 }
 /**
  * @param MvcEvent       $event
  * @param Request        $request
  * @param Response       $response
  * @param FlashMessenger $flashMessenger
  * @param RouteInterface $router
  * @param Translator     $translator
  *
  * @return bool
  */
 public function checkAcl(MvcEvent $event, Request $request, Response $response, FlashMessenger $flashMessenger, RouteInterface $router, Translator $translator)
 {
     $role = $this->guestRoleName;
     if ($this->auth->hasIdentity()) {
         $role = $this->auth->getIdentity()->getRole();
         if (!in_array($role, $this->allowedRoles)) {
             $role = $this->guestRoleName;
         }
     }
     $matchedRoute = $this->router->match($request);
     if (is_null($matchedRoute)) {
         return;
     }
     $params = $matchedRoute->getParams();
     $module = array_key_exists('__NAMESPACE__', $params) ? $params['__NAMESPACE__'] : null;
     $controller = array_key_exists('controller', $params) ? $params['controller'] : null;
     $action = array_key_exists('action', $params) ? $params['action'] : null;
     if ($module && $controller) {
         $module .= '.';
     }
     if ($action) {
         $controller .= '.';
     }
     $resource = str_replace('\\Controller', '', $module) . $controller . $action;
     $resource = strtolower(str_replace('\\', '.', $resource));
     if ($controller) {
         unset($params['controller']);
     }
     if ($action) {
         unset($params['action']);
     }
     if ($module) {
         unset($params['__NAMESPACE__']);
     }
     if (!$this->hasResource($resource)) {
         return true;
         if ($role == $this->guestRoleName) {
             $url = $router->assemble([], ['name' => 'aclGuestResourceNotFound']);
         } else {
             $url = $router->assemble([], ['name' => 'aclUserResourceNotFound']);
         }
         if (DEBUG) {
             $flashMessenger->addErrorMessage(sprintf($translator->translate('The requested resource %s does not exist'), $resource));
         } else {
             $flashMessenger->addErrorMessage($translator->translate('The requested resource does not exist'));
         }
         $response->setStatusCode(302);
         if (DEBUG) {
             echo '<div style="margin:150px auto; width: 50%; text-align:center; font-size:18px;"><h3>DEBUG IS ENABLED' . '</h3><br />Normally would auto-redirect to:<br /><br /><a style="font-size:24px;" href="' . $url . '">' . $url . '</a>';
             echo '</div>';
             die;
         }
         header('location: ' . $url);
         $event->stopPropagation();
         $event->setError('x');
         return;
     }
     if (!$this->isAllowed($role, $resource)) {
         if (DEBUG) {
             $flashMessenger->addErrorMessage(sprintf($translator->translate('You (%s) are not allowed to access this resource: %s'), $role, $resource));
         } else {
             $flashMessenger->addErrorMessage($translator->translate('You  are not allowed to access this resource'));
         }
         if ($role == $this->guestRoleName) {
             $url = $router->assemble([], ['name' => 'aclGuestNotAllowed']);
         } else {
             $url = $router->assemble([], ['name' => 'aclUserNotAllowed']);
         }
         $response->setStatusCode(302);
         if (DEBUG) {
             echo '<div style="margin:150px auto; width: 50%; text-align:center; font-size:18px;"><h3>DEBUG IS ENABLED' . '</h3><br />Normally would auto-redirect to:<br /><br /><a style="font-size:24px;" href="' . $url . '">' . $url . '</a>';
             echo '</div>';
             die;
         }
         header('location: ' . $url);
         $event->stopPropagation();
         $event->setError('x');
         return;
     }
     return true;
 }
Exemple #13
0
 /**
  * @param  Invoice $invoice
  * @return string[]
  */
 public function format(Invoice $invoice)
 {
     $statusFormat = static::$statusMap[$invoice->getStatus()];
     return [sprintf('<span class="label label-%s">%s</span>', $statusFormat['class'], $this->escaper->escapeHtml($statusFormat['label'])), sprintf('%s<br /><small>%s</small>', $this->escaper->escapeHtml($this->dateFormatter->format($invoice->getIssueDate())), $this->escaper->escapeHtml($this->getIssueDateAddition($invoice))), $invoice->getInvoiceNumber(), $this->escaper->escapeHtml($invoice->getClient()->getName()), $this->escaper->escapeHtml($this->numberFormatter->formatCurrency($invoice->getTotalAmount(), $invoice->getCurrencyCode())), sprintf('<a href="%s" class="btn btn-xs btn-default">Show</a>', $this->escaper->escapeHtmlAttr($this->router->assemble(['invoiceId' => $invoice->getId()], ['name' => 'invoices/show'])))];
 }