Symfony 3 在重置请求中遇到 FosUserBundle 问题


Symfony 3 Problems FosUserBundle in resetting request

我在 4 小时前收到此消息错误,我试图解决它,但我不知道问题出在哪里。也许所有文件都配置错误?登录是可以的。

安全.yml

security:
encoders:
    FOS'UserBundle'Model'UserInterface: sha512
role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
    fos_userbundle:
        id: fos_user.user_provider.username
firewalls:
    main:
        pattern: ^/
        form_login:
            default_target_path: /
            provider: fos_userbundle
            csrf_token_generator: security.csrf.token_manager
            remember_me: true   
        remember_me:
            secret:         %secret%
            #lifetime: 30000000
        logout:  true
        anonymous:    true
        logout:
            path: /logout
            target: /login

access_control:
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/register, role: ROLE_SUPER_ADMIN }
    - { path: ^/, role: ROLE_SUPER_ADMIN }
   # - { path: ^/listeUsers, role: ROLE_SUPER_ADMIN }
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
   # - { path: ^/admin/, role: ROLE_ADMIN }
   # - { path: ^/ajouter, role: ROLE_ADMIN }
    - { path: ^/index, role: IS_AUTHENTICATED_ANONYMOUSLY}

配置.yml

 imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
# Put parameters here that don't need to change on each machine where the app is deployed
#http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
    locale: en
framework:
    #esi:             ~
    #translator:      { fallbacks: ["%locale%"] }
    secret:          "%secret%"
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: ~
    form:            ~
    csrf_protection: ~
    validation:      { enable_annotations: true }
    #serializer:      { enable_annotations: true }
    templating:
        engines: ['twig']
        #assets_version: SomeVersionScheme
    default_locale:  "%locale%"
    trusted_hosts:   ~
    trusted_proxies: ~
    session:
        # http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
        handler_id:  session.handler.native_file
        save_path:   "%kernel.root_dir%/../var/sessions/%kernel.environment%"
    fragments:       ~
    http_method_override: true
    assets: ~
    translator: ~
# Twig Configuration
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"
# Doctrine Configuration
doctrine:
    dbal:
        driver:   pdo_mysql
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        # if using pdo_sqlite as your database driver:
        #   1. add the path in parameters.yml
        #     e.g. database_path: "%kernel.root_dir%/data/data.db3"
        #   2. Uncomment database_path in parameters.yml.dist
        #   3. Uncomment next line:
        #     path:     "%database_path%"
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
    transport: gmail
    host:      "%mailer_host%"
    username:  'digita****@gmail.com'
    password:  '*******'
    spool:     { type: memory }

#FOS USERBundle
fos_user:
    db_driver: orm
    firewall_name: main
    user_class: AppBundle'Entity'User
    from_email:
        address:        digita***.code@gmail.com
        sender_name:    DigitalCode - Sestem | Resetting Password

但是重置/请求不起作用。它停留在登录界面上。

第一顿汉兄弟,

你是对的,我在access_control中犯了一个错误,现在它可以工作,但使用这些没有 ReGex 的配置:

    access_control:
    - { path: ^/login, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/register, role: ROLE_SUPER_ADMIN }
    - { path: ^/, role: ROLE_SUPER_ADMIN }

问题解决了。

我认为您在access_control中配置错误:

看到这里

- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }

并将其与此进行比较

- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }

我认为这应该有效:

- { path: ^/resetting$, role: IS_AUTHENTICATED_ANONYMOUSLY }

现在它应该可以工作了。我无法完全解释它,但对我来说,由于缺少正则表达式分隔符,它似乎就像它没有像您想要的那样使用正则表达式。