Symfony简单的登录表单问题

时间:2016-04-26 13:38:14

标签: symfony security login symfony-2.8

我遇到登录问题。我已经阅读过Symfony doc。,有关stackoverflow和其他教程的主题。当我尝试使用Firefox或Chrome登录时,我第一次不会登录,但是第二次尝试我成功了。在IE中我根本不会登录。你可以帮忙吗?我没有想法。这是我的代码:

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

1 个答案:

答案 0 :(得分:0)

问题已解决。我已经探索了dev.log并且因为IE它写了这个错误:你的会话超时了,或者你已经禁用了cookie ...所以经过一些搜索我发现不可思议的不能在域名中(我有我的域名fc_hlinsko.local /app_dev.php/),所以我创建了新的Symfony项目和新的Bundle,现在一切似乎还可以。我还要在form_login下添加到我的security.yml这段代码:require_previous_session: false