I have the same problem with yours, because symfony2 internal security
mechanism, when the session time out, it automatically redirect the
page to /login, but for loginAction, I didn't response JSON format. i
searched google, there is few resource i could find, but I finally
have a solution for that one, we can check the authentication manually
before we continue processing our ajax request, and that router should
be unsecured.


js:

function isLogin() {
   // do some ajax request, and return true if authenticated
}



/ajax/login_check

        public function checkAction() {



                if($this->get('security.context')->getToken()->getUser()) {
                        $response = new Response(json_encode(array(
                                'result' => true
                        )));
                } else {
                        $response = new Response(json_encode(array(
                                'result' => false
                        )));
                }
                $response->headers->set('Content-Type', 'application/json');

                return $response;

        }


On May 10, 11:22 am, Dirk Louwers <dirk.louw...@stormlantern.nl>
wrote:
> Hi,
>
> In my Symfony application most requests expect a response returned in
> JSON format. I would like to be able to handle session timeouts
> differently based on the request. So instead of redirecting to the
> login page I would like to return some JSON to the client indicating
> that the session has timed out along with an URL the client should go
> to to re-authenticate.
>
> I would love to know where the "magic" happens that intercepts the /
> login_check pattern (if default) and how I can override it's behavior.
>
> Best,
>
> Dirk Louwers

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to