当拒绝访问 Neos 中的节点或方法时,如何显示自定义 404 页面?
How can I show a custom 404 page when access is denied to a node or method in Neos?
我们正在制作一个论坛,未注册的用户应该拒绝访问。我想为那里不允许的用户显示正确的错误消息 - 而不是异常。我如何在 Neos 2.0 中实现这一点?
读取和写入访问都应被拒绝。也许拒绝访问论坛所在的节点更容易?但是那不需要对节点路径进行硬编码吗?
当前 Policy.yaml
:
privilegeTargets:
'TYPO3\Flow\Security\Authorization\Privilege\Method\MethodPrivilege':
'My.Package:PostControllerLoggedInActions':
matcher: 'method(My\Package\PostController->(index|new|create)Action(.*))'
roles:
'TYPO3.Flow:Everybody':
privileges:
-
privilegeTarget: 'My.Package:PostControllerLoggedInActions'
permission: DENY
'My.Package:User':
privileges:
-
privilegeTarget: 'My.Package:PostControllerLoggedInActions'
permission: GRANT
编辑:这里有一些关于(除其他外)如何创建自定义 404 页面的幻灯片:https://speakerdeck.com/aertmann/tasty-recipes-for-every-day-neos
编辑 2:使用 Flow 异常处理程序?
您可以尝试在根目录下设置Configuration/Settings.yaml
。您可以通过状态代码(如示例)或异常 class:
来完成
TYPO3:
Flow:
# you have already persistence
# and maybe other stuff under flow
# just add it below them but still under TYPO3.Flow
error:
exceptionHandler:
renderingGroups:
accessRestricted:
matchingStatusCodes: [ 401, 403]
options:
templatePathAndFilename: 'resource://TYPO3.Neos/Private/Templates/Error/Index.html'
layoutRootPath: 'resource://TYPO3.Neos/Private/Layouts/'
format: 'html'
variables:
errorTitle: 'Restricted Area'
errorDescription: 'Go home boy.'
我们正在制作一个论坛,未注册的用户应该拒绝访问。我想为那里不允许的用户显示正确的错误消息 - 而不是异常。我如何在 Neos 2.0 中实现这一点?
读取和写入访问都应被拒绝。也许拒绝访问论坛所在的节点更容易?但是那不需要对节点路径进行硬编码吗?
当前 Policy.yaml
:
privilegeTargets:
'TYPO3\Flow\Security\Authorization\Privilege\Method\MethodPrivilege':
'My.Package:PostControllerLoggedInActions':
matcher: 'method(My\Package\PostController->(index|new|create)Action(.*))'
roles:
'TYPO3.Flow:Everybody':
privileges:
-
privilegeTarget: 'My.Package:PostControllerLoggedInActions'
permission: DENY
'My.Package:User':
privileges:
-
privilegeTarget: 'My.Package:PostControllerLoggedInActions'
permission: GRANT
编辑:这里有一些关于(除其他外)如何创建自定义 404 页面的幻灯片:https://speakerdeck.com/aertmann/tasty-recipes-for-every-day-neos
编辑 2:使用 Flow 异常处理程序?
您可以尝试在根目录下设置Configuration/Settings.yaml
。您可以通过状态代码(如示例)或异常 class:
TYPO3:
Flow:
# you have already persistence
# and maybe other stuff under flow
# just add it below them but still under TYPO3.Flow
error:
exceptionHandler:
renderingGroups:
accessRestricted:
matchingStatusCodes: [ 401, 403]
options:
templatePathAndFilename: 'resource://TYPO3.Neos/Private/Templates/Error/Index.html'
layoutRootPath: 'resource://TYPO3.Neos/Private/Layouts/'
format: 'html'
variables:
errorTitle: 'Restricted Area'
errorDescription: 'Go home boy.'