我使用过FOSUser Bundle,我想手动创建并使用always_remember_me cookie登录用户。我试过Create a symfony2 remember me cookie manually (FOSUserBundle)但它不起作用。我检查了FOSUSER设置的cookie,它是166B但是我用上面提到的功能创建的cookie是不同的。请帮助我
在security.yml中我有
encoders:
FOS\UserBundle\Model\UserInterface: sha512
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
logout: true
anonymous: true
remember_me:
key: "%secret%"
lifetime: 31104000 # in seconds
secure: false
always_remember_me: true
并在控制器中
$security = $this->get('security.context');
$providerKey = $this->container->getParameter('fos_user.firewall_name');
$key = $this->getParameter('secret'); // your security key from parameters.yml
$response = new Response();
$rememberMeToken = new RememberMeToken($user, $providerKey, $key, $user->getRoles());
$security->setToken($rememberMeToken);
$hash = hash('sha512', get_class($user) . $user->getUsername() . (time() + 31104000) . $user->getPassword() . $key, true);
$str = base64_encode(get_class($user) . ':' . base64_encode($user->getUsername()) . ':' . (time() + 31104000) . ':' . $hash);
$rememberMe = new Cookie('REMEMBERME', $str, (time() + 31104000), '/', null, false, true);
$response->headers->setCookie($rememberMe);
$response->send();
return new Response('hello');
它设置记住我的令牌,但它无效