简体   繁体   中英

Symfony simple login form issue

I got a problem with logging in. I have already read Symfony doc., topics on stackoverflow and other tutorials. When I try to log in with Firefox or Chrome, for the first time I won't login but on 2nd try I succeed. In IE I won't log in at all. Can u pls help? I'm out of ideas. Here is my code:

index.html.twig

<form action="{{ path('login_check') }}" method="post">
  <input type="text" id="username" name="_username" placeholder="{{ 'INDEX_LOGIN_USERNAME'|trans }}" />
  <input type="password" id="password" name="_password" placeholder="{{ 'INDEX_LOGIN_PASSWORD'|trans }}" />
  {#<input type="hidden" name="_target_path" value="/admin" />#}
  <button type="submit"></button>
</form>

routing.yml

login:
    path: /login
// without next line (defaults) I receive an error: Unable to find the controller for path "/login". The route is wrongly configured.
    defaults: { _controller: FC_Hlinsko_Bundle:Default:index } 
    options: { i18n: false }

logout:
    path: /logout
    options: { i18n: false }

homepage:
    path:     /
    defaults: { _controller: FC_Hlinsko_Bundle:Default:index }

admin:
    path:     /admin
    defaults: { _controller: FC_Hlinsko_Bundle:Admin:index }

security.yml

security:
    providers:
        in_memory:
            memory:
                users:
                    admin:
                        password: $2y$12$aE7n0XduDqfYd5xZVfm.G.uiIZSMUCdtPxfz6VRgdBKrU2ihxcC7i
                        roles: 'ROLE_ADMIN'
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
            anonymous: true

        secured_area:
            pattern:    ^/
            form_login:
                check_path: /login_check
                login_path: login
            logout:
                path:   logout
                target: homepage
            anonymous: ~

    access_control:
        # require ROLE_ADMIN for /admin*
        - { path: /login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: /admin, roles: ROLE_ADMIN }

    encoders:
        Symfony\Component\Security\Core\User\User:
            algorithm: bcrypt
            cost: 12

PROBLEM SOLVED. I have explored dev.log and because of IE it wrote this error: Your session has timed out, or you have disabled cookies... So after some searching I discovered the undescore cannot be in domain name (I had my domain fc_hlinsko.local/app_dev.php/), so I created new Symfony project and new Bundle and everything seems to be ok for now.. Also I had to add to my security.yml under form_login this code: require_previous_session: false

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