How to go back to referer after login failure?

后端 未结 1 1019
孤城傲影
孤城傲影 2020-12-08 04:56

For login success there is a parameter use_referer: true. For login failure there is only failure_path, which isn\'t what I\'m looking for.

1条回答
  •  执念已碎
    2020-12-08 05:38

    I solved it.

    There is solution: How to disable redirection after login_check in Symfony 2

    and here is code which solves my problem:

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

    to handle events add to security.yml for example:

    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 
    

    and to config.yml:

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

    0 讨论(0)
提交回复
热议问题