Skip to content

Instantly share code, notes, and snippets.

@hissy
Created July 5, 2021 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hissy/4ddc548c8b38c3ce500376d55ed7bc83 to your computer and use it in GitHub Desktop.
Save hissy/4ddc548c8b38c3ce500376d55ed7bc83 to your computer and use it in GitHub Desktop.
[concrete5][V8] Keep query parameters on forwarding to login page from page forbidden
<?php
namespace Application\Controller\SinglePage;
use Concrete\Core\Http\ResponseFactoryInterface;
use Concrete\Core\Url\Resolver\Manager\ResolverManagerInterface;
use Concrete\Core\Url\UrlImmutable;
use Concrete\Core\User\User;
use Symfony\Component\HttpFoundation\Response;
class PageForbidden extends \Concrete\Controller\SinglePage\PageForbidden
{
/**
* {@inheritdoc}
*/
protected function checkRedirectToLogin()
{
$result = null;
$user = $this->app->make(User::class);
if (!$user->isRegistered()) {
$config = $this->app->make('config');
if ($config->get('concrete.permissions.forward_to_login')) {
/** @var UrlImmutable $destination */
$destination = $this->app->make(ResolverManagerInterface::class)->resolve(['/login']);
/**
* Keep query parameters like ?utm_source=sns
*/
$destination = $destination->setQuery($this->request->query);
$result = $this->app->make(ResponseFactoryInterface::class)->redirect($destination, Response::HTTP_FOUND);
}
}
return $result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment