iPhone 上的 Rails 存在 JQTouch 登录问题

发布于 2024-09-12 17:51:59 字数 698 浏览 2 评论 0原文

我有一个使用 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 技术交流群。

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

发布评论

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

评论(1

好久不见√ 2024-09-19 17:51:59

免责声明:我对 RoR 还很陌生,所以这是我最好的猜测,可能完全错误......

我注意到在你的 app/views/dashboard 中你有index.html.erbindex.mobile.erb,所以我假设您使用 .mobile 后缀来获取 iPhone 特定的移动页面。在您的 lib/authenticated_system.rb 中,您的拒绝访问方法是:

  def access_denied
      respond_to do |format|
        format.html do
          store_location
          redirect_to new_session_path
        end
        # format.any doesn't work in rails version < http://dev.rubyonrails.org/changeset/8987
        # you may want to change format.any to e.g. format.any(:js, :xml)
        format.any do
          request_http_basic_authentication 'Web Password'
        end
      end
    end

每当未经授权的用户尝试访问内容时,就会调用此方法(请参阅您的 authorized 方法以了解用户的资格经授权)。此方法根据请求的格式响应请求。即任何 .html 请求都会命中 format.html do 块。由于没有 format.mobile 块,所有 .mobile 请求最终都会到达 format.any 块。这会导致您在问题中解释的行为:

不同的是在桌面上
版本我输入登录详细信息
直接进入我制作的登录表单,
但在iPhone上jqtouch版本a
iPhone UI 中的弹出窗口请求
登录信息。

两者之间的另一个区别是 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 have index.html.erb and index.mobile.erb, so I'm assuming that you're using a .mobile suffix for getting your iPhone specific mobile pages.. In your lib/authenticated_system.rb, your access denied method is:

  def access_denied
      respond_to do |format|
        format.html do
          store_location
          redirect_to new_session_path
        end
        # format.any doesn't work in rails version < http://dev.rubyonrails.org/changeset/8987
        # you may want to change format.any to e.g. format.any(:js, :xml)
        format.any do
          request_http_basic_authentication 'Web Password'
        end
      end
    end

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 the format.html do block. Since there's no format.mobile block, all .mobile requests end up hitting the format.any block. This results in the behavior you explained in your question:

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 other difference between the two is that format.html creates a session, while format.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 the format.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!

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