donglu8549 2016-12-12 16:57
浏览 78
已采纳

Symfony + Angular:重定向到登录页面

So, I'm using angular 1.5.9 and Symfony 2.8 in my project. Also FOSUserBundle is in use, but I'm not sure if it's matters.

Currently I need to logout user after 10 minutes inactivity. So, I want to use a solution as described here

And here is a problem I encountered - as long as I using angular and all my requests are asyncronous after this line is executed

$event->setResponse(new RedirectResponse($this->router->generate('fos_user_security_login')));

I'm not being redirected to login page. I was thinking about it but can't figure out what can I do without rewriting my each $http request in order to be able to handle redirect response.

  • 写回答

1条回答 默认 最新

  • dongmie3987067 2016-12-14 09:21
    关注

    I think you can use http interceptor to solve this problem. When the user is disconnected if he wants to get protected resource your backend have to return status code 401. So in your interceptor when status code 401 is returned you will redirect your user on the login page.

    kris

    Doc angular : https://docs.angularjs.org/api/ng/service/$http

    Exemple : http://www.webdeveasy.com/interceptors-in-angularjs-and-useful-examples/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料