gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 00:47:27 24 4
gpt4 key购买 nike

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

我记得在 Railscast 中,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 "Sign in with Facebook", "/auth/facebook" %>

另请参阅RailsCasts tagged with authentication

关于ruby-on-rails - 用于要求登录的 OmniAuth before_filter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4477745/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com