iPhone 上的 Rails 存在 JQTouch 登录问题
我有一个使用 jqtouch 的具有移动视图的 Rails 应用程序。如果在 iPhone 上查看应用程序,则加载 application.mobile.erb 来代替默认的 application.HTML.erb。
除了登录之外,一切正常。用户可以登录并查看内容。但是,他们每次加载网站时都必须登录。有没有办法让 iPhone 将凭据存储为 cookie 或类似内容?
我注意到,如果我在 iPhone 上查看桌面版本并登录,我的登录凭据会被存储,这样我就不必每次都登录。一旦我切换到 iPhone 特定的 jqtouch 版本,我每次都必须登录。
不同之处在于,在桌面版本上,我直接将登录详细信息输入到我制作的登录表单中,但在 iPhone jqtouch 版本上,iPhone UI 中的弹出窗口会请求登录信息。
该应用程序使用 Restful Authentication 插件: http://github.com/technoweenie/restful-authentication
谢谢,
Danny
您可以在 github 上查看该应用程序:
www.github.com/dannyweb/baseapp2
I have a rails app with a mobile view using jqtouch. If the application is viewed on an iPhone application.mobile.erb loads in place of the default application.HTML.erb.
Everything works fine, except the login. Users can login and then view the content. However, they have to login everytime they load the site. Is there a way of making the iPhone store the credentials as a cookie or similar?
I have noticed that if I view the desktop version on my iPhone and login, my login credentials are stored so I don't have to login everytime. Once I switch over to the iPhone specific jqtouch version I have to login every time.
The difference is that on the desktop version I enter the login details directly into the login form I made, but on the iPhone jqtouch version a popup from the iPhone UI requests the login information.
The application uses the Restful Authentication plugin: http://github.com/technoweenie/restful-authentication
Thanks,
Danny
You can view the application on github:
www.github.com/dannyweb/baseapp2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
免责声明:我对 RoR 还很陌生,所以这是我最好的猜测,可能完全错误......
我注意到在你的
app/views/dashboard
中你有index.html.erb
和index.mobile.erb
,所以我假设您使用 .mobile 后缀来获取 iPhone 特定的移动页面。在您的lib/authenticated_system.rb
中,您的拒绝访问方法是:每当未经授权的用户尝试访问内容时,就会调用此方法(请参阅您的
authorized
方法以了解用户的资格经授权)。此方法根据请求的格式响应请求。即任何.html
请求都会命中format.html do
块。由于没有format.mobile
块,所有 .mobile 请求最终都会到达format.any
块。这会导致您在问题中解释的行为:两者之间的另一个区别是
format.html
创建会话,而format.any
仅请求凭据而不创建会话。您是否考虑过添加
format.mobile
块来指定身份验证系统应如何处理 .mobile 请求,以便创建会话(类似于format.html
块)?您甚至可以尝试使用相同的 request_http_basic_authentication 方法(以便 iPhone UI 请求凭据),但随后对提交的凭据执行某些操作以创建会话或 cookie。再说一次,我可能完全没有根据,但希望我的回答利大于弊!
Disclaimer: I'm fairly new to RoR, so this is my best guess and may be totally off...
I noticed that in your
app/views/dashboard
you haveindex.html.erb
andindex.mobile.erb
, so I'm assuming that you're using a .mobile suffix for getting your iPhone specific mobile pages.. In yourlib/authenticated_system.rb
, your access denied method is:This method gets called whenever an unauthorized user tries to access content (see your
authorized
method to see what qualifies a user as authorized). This method responds to requests based on the format requested.. i.e. any.html
requests hit theformat.html do
block. Since there's noformat.mobile
block, all .mobile requests end up hitting theformat.any
block. This results in the behavior you explained in your question:The other difference between the two is that
format.html
creates a session, whileformat.any
only requests credentials and does not make a session.Have you considered adding a
format.mobile
block to specify how the authentication system should handle .mobile requests so that a session is created (similar to theformat.html
block)? You could even try using the same request_http_basic_authentication method (so that the iPhone UI request the credentials), but then do something with the submitted credentials to create a session or cookie.Again, I may be totally off base, but hopefully my answer does more help than harm!