【发布时间】:2016-02-17 09:58:39
【问题描述】:
我正在使用 SailsJS 和 AngularJS 来构建一个 Web 应用程序。该应用程序需要会话来跟踪任何用户的登录状态。我找到了这个tutorial 并添加了一个位于/view 文件夹中的index.ejs 视图。在index.ejs 中有一个Angular ng-view 引用assets/templates 文件夹中的html 模板。
还有一个route.js来处理客户端的模板路由:
angular.module('myApp', ['ngRoute'])
.config(['$routeProvider',function($routeProvider){
$routeProvider.when('/profile',{
templateUrl:'/templates/profile.html',
controller:'profileController as profileCtrl',
resolve:{
checkSession: function($location){
if(/* Check session status */){
alert("You can access profile.html");
}else{
$location.path('/login');
alert("You don't have access here");
}
}
}
})
.otherwise({redirectTo:'/'});
}]);
路由可以在请求/profile时将用户重定向到登录页面。但是,当用户请求localhost:1337/templates/profile.html 时,他们仍然可以获得 html,因为/assets 文件夹对 Internet 上的所有用户开放。我是否可以使用 Angular ng-view,以及将模板保存在安全的地方(类似于 Sails 模板)?例如,当用户登录时,服务器会提供一些模板,否则会提供其他模板。
如何处理这类权限问题? 感谢您的帮助!
【问题讨论】:
标签: javascript angularjs templates session sails.js