Backbone.js的+ require.js +用户认证 [英] backbone.js + require.js + user authentication
问题描述
开始学习Backbone.js的和require.js。
Started learning backbone.js and require.js.
不知道如何为构建Web应用程序文件,用户身份验证。
Not sure how to structure files for web app with user authentication.
看来它应该流是这样的:
Seems it should flow like this:
- 在应用程序初始化,查询服务器检查身份验证会话状态;
- 问:#1:我应该在哪里写这篇之后的init会话code - 在/js/app.js
- 问:2:?我应该使用jQuery阿贾克斯这一点,或者有更好的方法Backbone.js的(我见过的引用来获得(),取(),例子中的toJSON())
- 问:3:如何/我在哪里初始化这个模型,这样我可以在整个模块访问这些数据? IE浏览器。我有一个观点,为isLoggedIn.html将读取你好%的用户名%!退出显示模板。我想从这个模型访问用户名字段中。目前,我只看到了如何引用它在视图的定义[]创建一个新的模式,所以我不知道如何访问已初始化过程中创建的模型。
- 问:#4:我怎么有jquery.cookies.js插件到这个requirejs应用程序,这样我可以在以后使用$ .cookies像往常一样?我应该加入这个插件的定义[]列表?我必须把它添加到/js/jquery/loader.js文件?
感谢您的帮助。
编辑:我从<一个使用的文件href=\"https://github.com/thomasdavis/backbonetutorials/tree/gh-pages/examples/modular-backbone\">modular-backbone例如创建我的web应用程序。所以,当我谈论/js/app.js和js / router.js,这就是我指的是文件。
I used the files from modular-backbone example to create my web app. So when I am talking about /js/app.js and js/router.js, that's the files I refer to.
推荐答案
我在同样的情况也是如此。
我发现这个帖子而且好像做一些事情之前,每个请求是使用该解决方案最好的选择。
I'm in the same situation as well. I found this post and it seems like the best option to do something before every request is to use this solution.
访问和URL除/登录之前,我会通过cookie来验证或运行login视图。
Before accessing and URL except /login, I'm going to authenticate by cookie or run the login view.
关于包括其他文件夹(jQuery的饼干)的方式 - 只使用require.js机制:
About the way to include other folders (jQuery cookie)- just use the require.js mechanism:
- 在你的主文件'require.config' - >'路径'添加插件位置(jqueryCokkie:)
- 在您的视图下的定义添加路径名('jqueryCookie'),并把它传递给finction
- 的.js文件应该在以下结构(我试过贴code的例子在这里,但有问题...)。
- In your main file 'require.config' -> 'paths' add the plugin location (jqueryCokkie:)
- In your view under 'define' add the path name ('jqueryCookie') and pass it to the finction
- The .js file should be in the following structure (I tried to paste the code example here, but got problems...).
这篇关于Backbone.js的+ require.js +用户认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!