Skip to content

Commit

Permalink
Check webtrees rewrite_urls value during sign in. Fixes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
miqrogroove committed May 12, 2022
1 parent d68f08c commit 6158899
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions module.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Fisharebest\Webtrees\Module\AbstractModule;
use Fisharebest\Webtrees\Module\ModuleCustomInterface;
use Fisharebest\Webtrees\Module\ModuleCustomTrait;
use Fisharebest\Webtrees\Validator;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
Expand Down Expand Up @@ -62,10 +63,15 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
if ($request->getAttribute('route')->name === LoginPage::class) {
$params = $request->getQueryParams();
$url = $params['url'] ?? '';
if (substr_compare($url, '/my-page', -8) === 0) {
$params['url'] = substr($url, 0, -8);
$request = $request->withQueryParams($params);
}
if (Validator::attributes($request)->boolean('rewrite_urls', $default = false)) {
$end = '/my-page';
} else {
$end = '%2Fmy-page';
}
if (substr_compare($url, $end, -strlen($end)) === 0) {
$params['url'] = substr($url, 0, -strlen($end));
$request = $request->withQueryParams($params);
}
}

return $handler->handle($request);
Expand Down Expand Up @@ -108,7 +114,7 @@ public function customModuleAuthorName(): string
*/
public function customModuleVersion(): string
{
return '1.0.02';
return '1.0.03';
}

/**
Expand Down

0 comments on commit 6158899

Please sign in to comment.