简体   繁体   中英

Symfony 3 Problems FosUserBundle in resetting request

I had this message error 4 hours ago and I tried to resolve it but I didn't know where is the problem. Maybe all files are wrong configured? Login is OK.

security.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}

config.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

But resetting/request doesn't work. It stayed on the login interface.

First Thunks Brother ,

u are right i make a mistake in the access_control , now it's working but with those configurations without 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 }

Problem Solved.

I think you have a misconfiguration in access_control :

see this

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

and compare it with this

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

I think this should work:

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

Now it should be working. I can't explain it completely but for me since the regex delimiter is missing it seems to be like its used as given not as regex as you wanted to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM