简体   繁体   English

Symfony 3未设置记住我的cookie

[英]Symfony 3 does not set remember me cookie

I am following How to Add "Remember Me" Login Functionality , which should be straight forward, but not so. 我正在关注如何添加“记住我”登录功能 ,这应该很简单,但事实并非如此。

I also checked this question , among others. 我还检查了这个问题 ,等等。

I checked that the login form is correctly posting the field _remember_me , but Symfony somehow is not intercepting it and creating the cookie. 我检查了登录表单是否正确发布了_remember_me字段,但是Symfony某种程度上没有拦截它并创建cookie。

I went to the class that, I believe, sets the cookie, /vendor/symfony/src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeService.php , and it seems that nothing is happening over there. 我去上了我认为设置cookie的类,/ /vendor/symfony/src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeService.php ,似乎那里什么也没有发生。 I tried to var_dump or put on a session variable some of the arguments that build the cookie, to no avail. 我试图将var_dump或放在会话变量上以构建cookie的一些参数都无济于事。

The login as such is working properly. 这样的登录正常工作。

I am using Guard Authenticator. 我正在使用Guard Authenticator。

Here's the code: 这是代码:

security.yml 安全性

security:
encoders:
    UsedBundle\Entity\User: 
        algorithm: bcrypt
providers:
    db_provider:
        entity:
            class: UsedBundle:User
            property: email
            manager_name: used

firewalls:
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

    main:
        anonymous: ~
        provider: db_provider
        form_login: 
            login_path: /
            username_parameter: _email
            check_path: /login_check
            use_referer: true
        guard:
            authenticators:
                - app.form_login_authenticator 
        logout:
            path:   /logout
            target: /
        remember_me:
            secret: '%secret%'
            secure: false #change this to true if HTTPS
access_control:
    - { path: ^/admin, roles: ROLE_ADMIN }
    - { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY }

The login form: 登录表单:

{% if error is defined and error is not null %}
{{ dump(error) }}

<div>{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% else %}
<form action="" method="post" name="login_form" id="login_form" >
    <div class="contact" >
        <input type="email" id="email" name="_email" class="form-control" placeholder="e-mail" value="{% if last_username is defined %}{{ last_username }} {% endif %}" />
    </div>
    <div class="contact" >
        <input type="password" id="password" name="_password" placeholder="mot de passe" />
    </div>
    <div id="captcha_signup"></div>
    <div id="remember_me">
        <label for="remember">Se souvenir de moi </label>
        <input type="checkbox" id="remember_me" name="_remember_me" />
        <p id="a_recovery">mot de passe oubliée?</p>
    </div>
    <div>
        <button type="submit" class="sub_ok btn" name="submit" >Valider</button>
    </div>
</form>  
{% endif %}

Your custom authenticator that extends either AbstractGuardAuthenticator or AbstractFormLoginAuthenticator needs to return true; 扩展AbstractGuardAuthenticatorAbstractFormLoginAuthenticator自定义身份验证器需要return true; in supportsRememberMe() supportsRememberMe()

public function supportsRememberMe()
{
    return true;
}

If your code already has this in it, please share your full authenticator implementation and output from dev.log from the moment you go to the login page and hit that submit button. 如果您的代码中已经包含此代码,则从您进入登录页面并单击该提交按钮的那一刻起,请共享您的完整身份验证器实现和dev.log的输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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