用户是否已登录? (安全认证)

发布于 2024-07-29 06:41:55 字数 101 浏览 3 评论 0原文

我使用了restful-authentication,并且有“公共”布局和完全不同的“成员”布局。 当有人访问我的根目录(默认为公开)时,我如何检查他们是否已登录并将其重定向到会员部分?

I have used restful-authentication and I have "public" layout and a completely different "members" layout. When someone visits my root (defaults to public) how can I check if they are logged in and redirect them to the member's section?

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

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

发布评论

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

评论(2

望她远 2024-08-05 06:41:55

RestfulAuthentication 提供了一些条件方法/帮助程序,其中包括名为 logged_in? 的方法/帮助程序。 如果用户已登录,则返回 true。
查看 authenticated_system.rb 文件以获取所有可用方法的列表。

RestfulAuthentication provides some conditional methods/helpers including one called logged_in?. It returns true if the user is logged in.
Check out the authenticated_system.rb file for the list of all available methods.

仅此而已 2024-08-05 06:41:55

您可以在 application_controller.rb 中定义这样的方法:

private
def require_user
  # logic to check if session exists and redirect if not
end

然后在需要用户登录的页面中添加以下内容:

before_filter :require_user  

我不熟悉restful-auth,所以我不知道需要进行的确切检查。

祝你好运。

You could define a method like this in application_controller.rb:

private
def require_user
  # logic to check if session exists and redirect if not
end

Then add the following in your pages that require that the user be logged in:

before_filter :require_user  

I'm not familiar with restful-auth so I don't know the exact check that would be required.

Good luck.

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