基于身份验证加载backbone.js资源
我正在构建我的第一个主干应用程序,尽管我正在执行身份验证服务器端,但有些功能未经身份验证的用户无法使用,但因为它们位于我的资产路径中,并且是主干文件的一部分,所以一切被加载。
有没有办法只加载用户实际能够使用的资源?
我使用 Rails 和 cancan 来管理这个服务器端。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将资产分成不同的组:任何人都可以使用的组,以及经过身份验证的用户可以使用的组。基本上只发送允许用户使用的代码。
我最近写了一篇关于使用 ASP.NET MVC 执行此操作的文章。同样的想法也适用于 Rails,尽管资产管道的使用使得实现方式有些不同:
http://lostechies.com/derickbailey/2012/01/26/modularity-and-security-in-composite-javascript-apps/
You need to split the assets out in to separate groups: a group that can be used by anyone, and a group that can be used by authenticated users. Only send the code that the user is allowed to use, basically.
I wrote a post about doing this with asp.net mvc recently. the same idea applies to rails, though the use of the asset pipeline makes the implementation a bit different:
http://lostechies.com/derickbailey/2012/01/26/modularity-and-security-in-composite-javascript-apps/
最好的方法是创建一个具有名为
requireLogin: true/false
的属性的基本视图。所有其他视图都应继承此视图,并且需要身份验证的视图应设置
requireLogin:true
,对于所有其他视图,此属性应为false
。之后,您应该处理该属性的身份验证基础。
The best way is to create a Base view with a property named
requireLogin: true/false
.All other views should inherit this view and the views which need authentication you should set
requireLogin:true
, for all others this property should befalse
.After this you should handle the authentication base of this property.