Created
July 5, 2021 09:16
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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