代码之家  ›  专栏  ›  技术社区  ›  pedram shabani

symfony安全登录(无效凭据。)

  •  1
  • pedram shabani  · 技术社区  · 7 年前

    我用的是Symfony3.4和php7.1

    我的应用程序有表单登录。一切看起来都很好 即使在本地,我也可以毫无问题地登录。 但是 主持我的应用程序显示 域相关参数设置有误 错误。

    # security.yml
    security:
        encoders:
            AdminBundle\Entity\User: bcrypt
        providers:
            our_db_provider:
                entity:
                    class: AdminBundle:User
                    property: username
    
    
        firewalls:
            # disables authentication for assets and the profiler, adapt it according to your needs
            dev:
                pattern: ^/(_(profiler|wdt)|css|images|js)/
                security: false
    
    
            main:
                anonymous: ~
                form_login:
                    login_path: login
                    check_path: login
                    csrf_parameter: _csrf_security_token
                    csrf_token_id: a_private_string
                    require_previous_session: true
                    post_only:      true
                remember_me:
                    secret:   '%secret%'
                    lifetime: 604800 # 1 week in seconds
                    path:     /
                logout:
                    path:   /logout
                    target: /login
                    invalidate_session: false
                    delete_cookies:
                        a: { path: null, domain: null }
                        b: { path: null, domain: null }
    
                http_basic: ~
                provider: our_db_provider
                            # activate different ways to authenticate
    
               # http_basic: ~
                            # http://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate
    
                            # form_login: ~
                            # http://symfony.com/doc/current/cookbook/security/form_login_setup.html
        access_control:
    
            - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
            - { path: ^/admin_Cp, roles: ROLE_ADMIN }
    
    
        role_hierarchy:
                ROLE_ADMIN:       ROLE_USER
                ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
    

       public function loginAction(Request $request, AuthenticationUtils $authenticationUtils)
        {
            // get the login error if there is one
            $error = $authenticationUtils->getLastAuthenticationError();
    
            // last username entered by the user
            $lastUsername = $authenticationUtils->getLastUsername();
    
            return $this->render('AdminBundle:User:login_user.html.twig', array(
                'last_username' => $lastUsername,
                'error'         => $error,
            ));
        }
    

    如果你想知道更多关于这个问题的信息,我可以马上更新这个问题

    0 回复  |  直到 7 年前