我正在使用 SailsJS 和 AngularJS 构建 Web 应用程序。该应用程序需要 session 来跟踪任何用户的登录状态。我找到了这个tutorial并添加一个位于 /view
文件夹中的 index.ejs
View 。在 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
文件夹对互联网上的所有用户开放。我是否可以使用 Angular ng-view 并将模板保存在安全的地方(类似于 Sails 模板)?例如,当用户登录时,服务器提供一些模板,否则提供其他模板。
如何处理此类权限问题? 感谢您的帮助!
最佳答案
实际上不需要给模板文件添加权限,因为它们只是html文件。您可以使用 Angular templateProvider 根据用户 Angular 色提供单独的模板页面。
关于javascript - 使用 SailsJS + AngularJS 时如何防止模板暴露,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35453355/