Symfony2 FOSUser登录清除缓存后

时间:2015-10-01 12:45:30

标签: symfony login fosuserbundle

我的FosUser登录有问题,这几天我尝试在导航栏中渲染我的登录html页面的控制器,登录工作正常。 现在我将我的网站放在服务器上,我清除缓存,登录后页面刷新而无需登录网站..

这是控制器

namespace FOS\UserBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;

class SecurityController extends Controller
{
public function loginAction(Request $request)
{
    /** @var $session \Symfony\Component\HttpFoundation\Session\Session */
    $session = $request->getSession();

    // get the error if any (works with forward and redirect -- see below)
    if ($request->attributes->has(SecurityContextInterface::AUTHENTICATION_ERROR)) {
        $error = $request->attributes->get(SecurityContextInterface::AUTHENTICATION_ERROR);
    } elseif (null !== $session && $session->has(SecurityContextInterface::AUTHENTICATION_ERROR)) {
        $error = $session->get(SecurityContextInterface::AUTHENTICATION_ERROR);
        $session->remove(SecurityContextInterface::AUTHENTICATION_ERROR);
    } else {
        $error = null;
    }

    if (!$error instanceof AuthenticationException) {
        $error = null; // The value does not come from the security component.
    }

    // last username entered by the user
    $lastUsername = (null === $session) ? '' : $session->get(SecurityContextInterface::LAST_USERNAME);

    $csrfToken = $this->has('form.csrf_provider')
        ? $this->get('form.csrf_provider')->generateCsrfToken('authenticate')
        : null;

    return $this->renderLogin(array(
        'last_username' => $lastUsername,
        'error'         => $error,
        'csrf_token' => $csrfToken,
    ));
}

/**
 * Renders the login template with the given parameters. Overwrite this function in
 * an extended controller to provide additional data for the login template.
 *
 * @param array $data
 *
 * @return \Symfony\Component\HttpFoundation\Response
 */
protected function renderLogin(array $data)
{
    return $this->render('FOSUserBundle:Security:login.html.twig', $data);
}

public function checkAction()
{
    throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.');
}

public function logoutAction()
{
    throw new \RuntimeException('You must activate the logout in your security firewall configuration.');
}
}

我该怎么办?

1 个答案:

答案 0 :(得分:0)

你做过:

app/console cache:clear --env=prod

或a:

app/console cache:clear

您应该将第一个用于生产环境

https://reformatcode.com/browse