长话短说:我正在为我的公司设置一个私人 Packagist 站点,我需要禁用用户注册 [用户由 Chef 创建],同时仍然允许 Github OAuth 连接。
我通过在以下路径中添加以下不可满足的条件来禁用常规注册页面routing.yml:
fos_user_register:
resource: '@FOSUserBundle/Resources/config/routing/registration.xml'
prefix: /register
condition: "1 == 0"
Run Code Online (Sandbox Code Playgroud)
但是我发现,如果您在没有先连接现有帐户的情况下尝试使用 Github 登录,那么下面会出现第二个注册表单,该注册表单由以下/connect/registration路由管理:
hwi_oauth_connect:
resource: '@HWIOAuthBundle/Resources/config/routing/connect.xml'
prefix: /connect
Run Code Online (Sandbox Code Playgroud)
中routing.yml,并且:
<route id="hwi_oauth_connect_registration" path="/registration/{key}">
<default key="_controller">HWIOAuthBundle:Connect:registration</default>
</route>
Run Code Online (Sandbox Code Playgroud)
这是在vendor/hwi/oauth-bundle/Resources/config/routing/connect.xml.
如何仅禁用/connect/registration而不修改connect.xml供应商文件夹中的 ?
复制文件内容'@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>
Run Code Online (Sandbox Code Playgroud)
在您的 中routing.yml,更改hwi_oauth_connect为:
hwi_oauth_connect:
resource: "routing_hwi_connect.xml"
prefix: /connect
Run Code Online (Sandbox Code Playgroud)
404当有人尝试访问它时,它应该返回 a 。
另外,肯定有更好的方法来允许/限制路由,也许可以通过创建预注册方法,然后查看SecurityBundle 配置,您可以在其中轻松地做一些好事。