0
我在我的Rails应用程序中使用了魔法宝石。 Oauth身份验证正在使用Google和Github服务。但是,如果用户有相同的电子邮件登录Google和Github,我的应用程序会忽略其他尝试登录,因为已使用的电子邮件已存储在数据库中。使用相同的电子邮件地址通过Oauth和Sorcery登录Rails应用程序
所以,我需要通过Oauth在我的应用程序中多次登录,即使不同服务中的电子邮件是相同的。我该怎么办?
我在我的Rails应用程序中使用了魔法宝石。 Oauth身份验证正在使用Google和Github服务。但是,如果用户有相同的电子邮件登录Google和Github,我的应用程序会忽略其他尝试登录,因为已使用的电子邮件已存储在数据库中。使用相同的电子邮件地址通过Oauth和Sorcery登录Rails应用程序
所以,我需要通过Oauth在我的应用程序中多次登录,即使不同服务中的电子邮件是相同的。我该怎么办?
你可以这样说:
put it in ./app/controller/oauths_controller.rb
高清回调
provider = auth_params[:provider]
if @user = login_from(provider)
redirect_to root_path, :notice => "Logged in from #{provider.titleize}!"
else
begin
@user = create_from(provider)
reset_session # protect from session fixation attack
auto_login(@user)
redirect_to root_path, :notice => "Logged in from #{provider.titleize}!"
rescue
provider_hash = sorcery_fetch_user_hash(provider)
user_email = provider_hash[:user_info]['email']
@user = User.find_by_email(user_email)
@user.authentications.create!(:provider => provider, :uid => provider_hash[:uid])
reset_session
auto_login(@user)
redirect_to root_path, :notice => "Logged in from #{provider.titleize}!"
rescue
redirect_to root_path, :alert => "Failed to login from #{provider.titleize}!"
end
end
末
也许这个帖子将帮助http://stackoverflow.com/questions/21658999/ omniauth-devise-error-validation-failed-email-has-been-taken – chumakoff
感谢您的帮助!但是也许有什么方法可以用Sorcery宝石来解决这个问题? –