2014-09-01 67 views
0

我已经创建了带有HTML和Javascript的angularjs应用程序。但现在我需要确保应用程序。如果有任何要求涉及到任何HTML网页(或HTML模板或JavaScript):用户认证angularjs单页面应用程序

  • /主
  • /产品
  • /类别

应该重定向如果用户到登录页面,未认证。我没有使用Asp.net或PHP或Java页面。我可以在Linux平台上发布我的应用程序。

如何保护我的angularjs单页应用程序。

+0

有几十个与此相关的问题。请搜索一下...关键字:angular-app或http-auth-interceptor – 2014-09-01 13:44:16

+0

你在服务器端有什么? – 2014-09-01 13:45:26

+0

服务器操作系统是ubuntu,并且安装了nginx + PHP,apache没有安装 – barteloma 2014-09-01 13:46:47

回答

0

你可以用这个做的最好的事情是检查每个路由变化的用户认证。但是,你做客户端认证是非常容易的。但后来这也可以是伪代码:

$rootScope.$on("$routeChangeStart", function (event, next, current) { 
     $rootScope.error = null; 
     if (!Auth.authorize(next.access)) {//check if the user is authorized to go to next page 
      if(Auth.isLoggedIn()) $location.path('/');//if not authorized and is logged in then send him to home page 
      else     $location.path('/login');//if not logged in ask for login 
     } 
    }); 

为了获得良好的柔韧性尝试使用UI-Router和是GitHub上的项目,可以帮助您开始angular-client-side-auth

相关问题