为了账号安全,请及时绑定邮箱和手机立即绑定

Symfony 5 不断从注册路由重定向

Symfony 5 不断从注册路由重定向

PHP
慕婉清6462132 2023-07-21 15:42:11
我正在尝试构建一个登录页面,在我想登录用户后它就可以工作了,所以我使用了 make: Auth 似乎但现在 Symfony 5 不断从注册路由重定向到登录,而不先将用户保存在数据库中,当提交表单时,它在我运行 make auth cmd 之前就可以工作大部分代码与用户身份验证有关这是我使用的指南https://symfony.com/doc/current/security/form_login_setup.html在 Symfony 文档上我想这就是它搞砸的原因当您提交表单时,LoginFormAuthenticator 将拦截请求,从表单中读取电子邮件(或您正在使用的任何字段)和密码,找到 User 对象,验证 CSRF 令牌并检查密码security:    encoders:        App\Entity\User:            algorithm: auto     providers:        users:            entity:                 class: App\Entity\User                property: Username    firewalls:        dev:            pattern: ^/(_(profiler|wdt)|css|images|js)/            security: false        main:            access_denied_handler: App\Security\AccessDeniedHandler            anonymous: false            lazy: true            provider: users            form_login:                login_path: app_login                check_path: app_login            guard:                authenticators:                    - App\Security\AuthAuthenticator            logout:                path: app_logout                # where to redirect after logout                # target: app_any_route            # activate different ways to authenticate            # https://symfony.com/doc/current/security.html#firewalls-authentication            # https://symfony.com/doc/current/security/impersonating_user.html            # switch_user: true    # Easy way to control access for large sections of your site    # Note: Only the *first* access control that matches will be used    access_control:        # - { path: ^/admin, roles: ROLE_ADMIN }        # - { path: ^/profile, roles: ROLE_USER }
查看完整描述

1 回答

?
繁花不似锦

TA贡献1851条经验 获得超4个赞

您似乎在树枝表单上缺少 csrf_token 隐藏字段,如您提供的 Symfony 文档链接中所述:如何构建登录表单

  <input type="hidden" name="_csrf_token"
           value="{{ csrf_token('authenticate') }}"
    >

尽管我不推荐它,但如果您的应用程序不重要,另一种解决方案是禁用 csrf_checking - 只需从 AuthAuthenticator 中删除所有提及 CSRF 的内容即可。


查看完整回答
反对 回复 2023-07-21
  • 1 回答
  • 0 关注
  • 71 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信