Подтвердить что ты не робот

Как вернуться к рефереру после неудачи входа?

Для успеха входа в систему существует параметр use_referer: true. Для входа в систему существует только failure_path, чего я не ищу.

Второе: как это сделать и передать сообщение об ошибке?

Третья вещь: Как вернуться к рефереру после выхода из системы?

4b9b3361

Ответ 1

Я решил это.

Существует решение: Как отключить перенаправление после login_check в Symfony 2

и вот код, который решает мою проблему:

<?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);
    }
}

для обработки событий добавьте в security.yml например:

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 

и config.yml:

services:
    authentication_handler:
        class: Acme\MainBundle\Handler\AuthenticationHandler