gpt4 book ai didi

php - 禁用特定的 Symfony 路由

转载 作者:行者123 更新时间:2023-12-05 02:21:16 25 4
gpt4 key购买 nike

长话短说:我正在设置一个 private Packagist site对于我的公司,我需要禁用用户注册 [用户由 Chef 创建],同时仍允许 Github OAuth 连接。

我通过向 routing.yml 中的路由添加以下无法满足的条件来禁用常规注册页面:

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

但是我发现,如果您尝试在没有先连接现有帐户的情况下使用 Github 登录,则在 /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 configuration在这里您可以轻松地做好事。

关于php - 禁用特定的 Symfony 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35588963/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com