我使用FOSUserBundle注册新用户。
用户回答几个保存到会话中的问题。如果答案正确,则会将用户重定向到注册操作。注册后,用户被重定向到finalAction。 在finalAction中,我无法访问会话中的数据,但是当我重新加载页面时,数据就在那里。
有谁知道什么是错的?
我的registerAction()
中的一部分代码 $formHandler = $this->container->get('project_user.form.handler.registration');
$process = $formHandler->process(false);
if ($process)
{
$user = $form->getData();
$url = $this->container->get('router')->generate('project_user_check_register', array(
'url' => urlencode($pLink . '?from_register=1')
));
$response = new RedirectResponse($url, 301);
$authenticate = $this->authenticateUser($user, $response, true);
return $authenticate;
}
这里是authenticateUser方法
protected function authenticateUser(UserInterface $user, Response $response, $registration = false)
{
$expires = time() + 31536000;
$secret = $this->container->getParameter('secret');
$userClass = get_class($user);
$value = base64_encode(implode(':', array(
$userClass,
base64_encode($user->getUsername()),
$expires,
hash('sha256', $userClass.$user->getUsername().$expires.$user->getPassword().$secret)
)));
$response->headers->setCookie(
new Cookie(
'REMEMBERME',
$value,
$expires
)
);
try
{
$this->container->get('fos_user.security.login_manager')->loginUser(
$this->container->getParameter('fos_user.firewall_name'), $user, $response);
}
catch (AccountStatusException $ex)
{
// We simply do not authenticate users which do not pass the user
// checker (not enabled, expired, etc.).
}
if($registration)
{
/*
* remove the recommendation cookie
*/
if ($this->container->get('request')->cookies->get('recommendCookie'))
{
$cookie = new Cookie('recommendCookie', '_______', time() - 100);
$response->headers->setCookie($cookie);
}
}
return $response;
}