您好我只是按照本教程在我的应用中为Facebook和Google设置了omniauth:http://sourcey.com/rails-4-omniauth-using-devise-with-twitter-facebook-and-linkedin/ 这是我的OmniauthCallbacksController:
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def self.provides_callback_for(provider)
class_eval %Q{
def #{provider}
@user = User.find_for_oauth(env["omniauth.auth"], current_user)
if @user.persisted?
sign_in_and_redirect @user, event: :authentication
set_flash_message(:notice, :success, kind: "#{provider}".gsub(/_/," ").split[0...1].join(' ').capitalize) if is_navigational_format?
else
session["devise.#{provider}_data"] = env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
}
end
[:google_oauth2, :facebook].each do |provider|
provides_callback_for provider
end
def after_sign_in_path_for(resource)
#if resource.email_verified?
super resource
#else
# finish_signup_path(resource)
#end
end
# def google_oauth2
# raise request.env["omniauth.auth"]
# end
end
我想将已注册facebook或google(未登录,注册新帐户)的所有用户重定向到他们的用户个人资料页面,并提示他们要更改用户名,因为我将电子邮件设置为他们在注册时的用户名。我怎么能这样做?
答案 0 :(得分:1)
此行之后sign_in_and_redirect @user, event: :authentication
您可以使用omniauth添加此用户注册的cookie值。
cookies[:oA] = true
在after_sign_in_path_for(resource)
方法中检查Cookie的值是否为true,例如添加路径username_path(resource)
。