duankang5882 2017-03-29 01:17
浏览 148
已采纳

使用http post检查会话和重定向

I am still new to angularjs and trying to understand the concept. i have a working solution but i just need to make sure this is a secure way of doing it. i have a $rootScope.$on('$stateChangeStart', function(){} which sends a http post to a php file, this checks to see if it has session data and returns "1" being true and "0" being false. if false then i perform a $state.go('login'); which redirects to login page. This works exactly how i wish it to but just would like some further knowledge if this is secure enough.

  • 写回答

2条回答 默认 最新

  • dongluo3331 2017-03-29 02:07
    关注

    While there are several others way of authenticating the session data, your approach is fine as well.

    Enclose the $on in app.run method and check if user is on login page then avoid the $http call.

    app.run(function ($rootScope, $state) {
        $rootScope.$on('$stateChangeStart', function (event, next, nextParams, prev, prevParams) {
    
            //Check if already on login page do not check session
            if (next.name === 'login') {
                return;
            }
    
            //$http call to check session
        });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部