微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ruby-on-rails – OmniAuth before_filter,用于要求登录

是否可以使用OmniAuth在某些操作之前要求登录

我记得有一个轨道广播说Devise有一个before_filter,但是OmniAuth呢?

解决方法

你可以添加一个before_filter:
class ApplicationController < ActionController::Base

  before_filter :authenticate

  def authenticate
    redirect_to :login unless User.find_by_provider_and_uid(auth["provider"],auth["uid"])
  end
...
end

假设:
1.您已经定义了一个包含以下链接登录页面:<%= link_to“使用Facebook登录”,“/ auth / facebook”%>

另见RailsCasts tagged with authentication

原文地址:https://www.jb51.cc/ruby/264669.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐