我在關注How to Add "Remember Me" Login Functionality,應該是直截了當的,但並非如此。Symfony 3沒有設置記住我的cookie
我也檢查了this question,等等。
我檢查登錄表單是否正確發佈字段_remember_me
,但Symfony以某種方式不會攔截它並創建cookie。
我去了上課,我相信,它設置了cookie,/vendor/symfony/src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeService.php
,而且似乎在那裏沒有任何事情發生。我試圖var_dump或將一些會話變量放在構建cookie的參數上,但無濟於事。
這樣的登錄工作正常。
我正在使用Guard Authenticator。
下面的代碼:
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 }
登錄表單:
{% 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 %}