繁体   English   中英

禁用特定的Symfony路由

[英]Disable specific Symfony routes

简而言之:我正在为我的公司设置一个私有的Packagist站点 ,我需要禁用用户注册[用户由Chef创建],同时仍允许Github OAuth连接。

我通过在routing.yml为路由添加以下不可满足条件来禁用常规注册页面:

fos_user_register:
    resource: '@FOSUserBundle/Resources/config/routing/registration.xml'
    prefix: /register
    condition: "1 == 0"

但是我发现,如果您在没有先连接现有帐户的情况下尝试使用Github /connect/registration ,则/connect/registration下的第二个注册表单由路由管理:

hwi_oauth_connect:
    resource: '@HWIOAuthBundle/Resources/config/routing/connect.xml'
    prefix:   /connect

routing.yml ,和:

<route id="hwi_oauth_connect_registration" path="/registration/{key}">
    <default key="_controller">HWIOAuthBundle:Connect:registration</default>
</route>

vendor/hwi/oauth-bundle/Resources/config/routing/connect.xml

如何在不修改vendor文件夹中的connect.xml情况下仅禁用/connect/registration

复制文件'@HWIOAuthBundle/Resources/config/routing/connect.xml'并将其粘贴到新的app/config/routing_hwi_connect.xml

通过在新创建的文件中设置自定义检查来禁用路由:

<route id="hwi_oauth_connect_registration" path="/registration/{key}">
    <default key="_controller">HWIOAuthBundle:Connect:registration</default>
    <condition>1 == 0</condition>
</route>

在您的routing.yml ,将hwi_oauth_connect更改为:

hwi_oauth_connect:
    resource: "routing_hwi_connect.xml"
    prefix:   /connect

当有人试图访问它时它应该返回404

此外,肯定有更好的方法来允许/限制路由,可能是通过创建预注册方法,然后查看SecurityBundle配置 ,您可以轻松地做一些好事。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM