Rails Omniauth Facebook登录重定向注册 [英] Rails Omniauth Facebook login redirects to sign up
本文介绍了Rails Omniauth Facebook登录重定向注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
devise_for:users,:controllers => {:omniauth_callbacks => users / omniauth_callbacks}
我在application.html.erb中有这个:
<%= link_to,user_omniauth_authorize_path(:facebook,:origin =>root_url)%>
<%= link_to(image_tag(FB-Login.png),
user_omniauth_authorize_path(:facebook),:origin =>root_url,class:mycss)%>
我在application_controller.rb中有这个:
def after_sign_in_path_for(resource_or_scope)
Rails.logger.level = 0
logger.debugafter_sign_in_path_for
logger.debug会话:#{@ session.inspect}
logger.debugomniauth.origin:#{omniauth.origin}
logger.debugroot_url:#{root_url}
## if request.env [ 'omniauth.origin']
## request.env ['omniauth.origin']
request.env ['omniauth.origin'] || root_url
end
有趣的是日志语句没有显示在heroku日志中 - 像after_sign_in_path_for一样不叫??
任何帮助赞赏,
Slavko
解决方案
可能该用户已经存在?
尝试在持久性之前检查用户存在:
def facebook
@user = User.from_omniauth(request.env [omniauth.auth])
如果@user
sign_in_and_redirect @user, event => :认证#如果@user没有被激活,这将抛出
set_flash_message(:notice,:success,:kind =>Facebook)if is_navigational_format?
else
session [devise.facebook_data] = request.env [omniauth.auth]
redirect_to new_user_registration_url
end
end
for some reason my Omniauth Facebook login is redirecting to /users/sign_up#= - but otherwise appears to be working. I have this in routes.rb:
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
I have this in application.html.erb:
<%= link_to "", user_omniauth_authorize_path(:facebook, :origin=>"root_url") %>
<%= link_to(image_tag("FB-Login.png"),
user_omniauth_authorize_path(:facebook), :origin=>"root_url", class:"mycss") %>
I have this in application_controller.rb:
def after_sign_in_path_for(resource_or_scope)
Rails.logger.level = 0
logger.debug "after_sign_in_path_for"
logger.debug "Session: #{@session.inspect}"
logger.debug "omniauth.origin: #{omniauth.origin}"
logger.debug "root_url: #{root_url}"
## if request.env['omniauth.origin']
## request.env['omniauth.origin']
request.env['omniauth.origin'] || root_url
end
Funny thing is the log statements are not showing in the heroku logs - looks like after_sign_in_path_for is not called ??
Any help appreciated, Slavko
解决方案
Maybe that user already exist?
Try to check user existence prior to persistence:
def facebook
@user = User.from_omniauth(request.env["omniauth.auth"])
if @user
sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
这篇关于Rails Omniauth Facebook登录重定向注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文