Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Classes/Domain/Service/Neos/NeosRedirectTargetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ public function onAuthenticationSuccess(ControllerContext $controllerContext, Ac
// Neos only logic (configuration at node or via TS)
/** @var ActionRequest $actionRequest */
$actionRequest = $controllerContext->getRequest();
if ($actionRequest->getInternalArgument('__redirectAfterLogin')) {

if ($actionRequest->getHttpRequest()->hasArgument('forwardUrl') && strlen($actionRequest->getHttpRequest()->getArgument('forwardUrl'))) {
return $this->sanitizeForwardUrl($actionRequest->getHttpRequest()->getArgument('forwardUrl'));
} elseif ($actionRequest->getInternalArgument('__redirectAfterLogin')) {
return $this->getNodeLinkingService()
->createNodeUri($controllerContext, $actionRequest->getInternalArgument('__redirectAfterLogin'));
}
Expand Down Expand Up @@ -98,4 +101,12 @@ protected function getNodeLinkingService()
{
return $this->objectManager->get(LinkingService::class);
}

/**
* @param string $forwardUrl
* @return string
*/
protected function sanitizeForwardUrl(string $forwardUrl): string {
return filter_var($forwardUrl, FILTER_SANITIZE_URL);
}
}
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ loginform = Sandstorm.UserManagement:LoginForm {
}
```

### Via url parameter
When using the package within Neos, you can also use an url parameter to provide a redirect target, e.g. the site where
the user clicked on login. To do so, just append the parameter `forwardUrl` to your url. This url will be sanitized by
removing all characters which are not allowed in urls and then will be used before checking the noe properties.

URL example:
```
http://localhost/login.html?forwardUrl=http%3A//localhost/editor%3FeditMode%3D%22true%22
```

### Via custom RedirectTargetService
If redirecting to a specific controller method is still not enough for you, you can simply roll your own implementation of the
`RedirectTargetServiceInterface`. Just add the implementation within your own package and add the following lines to your `Objects.yaml`.
Expand Down