用户是否已登录? (安全认证)
我使用了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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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.您可以在 application_controller.rb 中定义这样的方法:
然后在需要用户登录的页面中添加以下内容:
我不熟悉restful-auth,所以我不知道需要进行的确切检查。
祝你好运。
You could define a method like this in application_controller.rb:
Then add the following in your pages that require that the user be logged in:
I'm not familiar with restful-auth so I don't know the exact check that would be required.
Good luck.