基于身份验证加载backbone.js资源

发布于 2025-01-08 02:54:09 字数 161 浏览 2 评论 0 原文

我正在构建我的第一个主干应用程序,尽管我正在执行身份验证服务器端,但有些功能未经身份验证的用户无法使用,但因为它们位于我的资产路径中,并且是主干文件的一部分,所以一切被加载。

有没有办法只加载用户实际能够使用的资源?

我使用 Rails 和 cancan 来管理这个服务器端。

I'm building my first backbone app, and though I'm doing my authentication server side, there are features that non-authenticated users are unable to use, but because they are in my asset path, and part of my backbone files, everything gets loaded.

Is there a way to load only the resources that a user is actually able to use?

I'm using Rails with cancan to manage this server-side.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

傲娇萝莉攻 2025-01-15 02:54:10

您需要将资产分成不同的组:任何人都可以使用的组,以及经过身份验证的用户可以使用的组。基本上只发送允许用户使用的代码。

我最近写了一篇关于使用 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/

冷弦 2025-01-15 02:54:10

最好的方法是创建一个具有名为 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 be false.

After this you should handle the authentication base of this property.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文