Tôi đã giải quyết.
Có giải pháp: How to disable redirection after login_check in Symfony 2
và đây là mã mà giải quyết vấn đề của tôi:
<?php
namespace Acme\MainBundle\Handler;
use Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
class AuthenticationHandler implements AuthenticationFailureHandlerInterface, LogoutSuccessHandlerInterface
{
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
$referer = $request->headers->get('referer');
$request->getSession()->setFlash('error', $exception->getMessage());
return new RedirectResponse($referer);
}
public function onLogoutSuccess(Request $request)
{
$referer = $request->headers->get('referer');
return new RedirectResponse($referer);
}
}
để xử lý các sự kiện thêm vào security.yml ví dụ:
form_login:
check_path: /access/login_check
login_path:/
use_referer: true
failure_handler: authentication_handler
logout:
path: /access/logout
target:/
success_handler: authentication_handler
và để cấu hình .yml:
services:
authentication_handler:
class: Acme\MainBundle\Handler\AuthenticationHandler
Nguồn
2012-01-30 14:44:30
Tại sao đường dẫn thất bại không phải là dấu nhắc đăng nhập? – JamesHalsall
vì tôi có thể đăng nhập từ mọi trang con. Tôi không có một mẫu đăng nhập trên url được chỉ định, vì vậy tôi không muốn chuyển hướng người dùng đến trang chủ khi anh ấy đăng nhập từ ví dụ như một trang hồ sơ người dùng khác. –