2017-08-15 72 views
3

我正在使用Symfony 3.3和FOSUserBundle 2.0。我无法使重置密码功能正常工作。我去请求重置页面,输入电子邮件或用户名,然后点击提交,它会将我重定向到登录页面,而不会在视图中显示任何错误。 我看着日志,它给我这个错误:FOSUserBundle重置密码不适用于模拟用户配置

security.DEBUG: Access denied, the user is not fully authenticated; redirecting to authentication entry point. {"exception":"[object] (Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException(code: 403): Access Denied. at .../vendor/symfony/symfony/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php:125)"} [] 

Security.yml:

security: 
encoders: 
    FOS\UserBundle\Model\UserInterface: sha512 

{...} 

firewalls: 
    main: 
     pattern: ^/ 
     form_login: 
      provider: fos_userbundle 
      csrf_token_generator: security.csrf.token_manager 
      default_target_path: /verifInit 
     logout:  true 
     anonymous: true 
     switch_user: 
      role: ROLE_ADMIN 
      provider: fos_userbundle 
      parameter: username 
    dev: 
     pattern: ^/(_(profiler|wdt)|css|images|js)/ 
     security: false 

providers: 
    in_memory: 
     memory: 
      users: 
       user: { password: userpass, roles: [ 'ROLE_USER' ] } 
       admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] } 
    fos_userbundle: 
     id: fos_user.user_provider.username 

access_control: 
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } 
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } 
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } 
    - { path: ^/admin/, role: ROLE_ADMIN } 

当我删除security.yml switch_user部分,它的工作好。你知道为什么吗?我需要我的项目的switch_user功能,所以我不能删除它。

+0

你可以发布security.yml的内容吗?和/或您是否在负责此操作的控制器中添加了任何与Auth相关的代码? – Vamsi

+0

我编辑了我的问题 –

+0

您没有更改用户实体? –

回答

0
switch_user: true 

security: 
    role_hierarchy: 
     ROLE_ADMIN: [ROLE_USER, ROLE_ALLOWED_TO_SWITCH] 

尝试这种方式。

+0

重置密码正在与您的参数!但它打破了切换用户。 我有这个错误:'开关用户失败:“用户名”1000“不存在。”' 但我有一个用户在我的数据库中用户名为1000. –

+0

我通过在'switch_user'中添加'provider:fos_userbundle'得到了它的工作。 –