用户注册时使用Facebook登录,Rails 5,Omniouth with Device

时间:2017-09-13 17:47:09

标签: ruby-on-rails facebook omniauth omniauth-facebook

我有这个用户模型:

def self.from_omniauth(auth)
    where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
        user.email = auth.info.email
        user.password = Devise.friendly_token[0,20]
        user.fname = auth.info.name   
        user.skip_confirmation!
    end
end

def self.new_with_session(params, session)
    super.tap do |user|
        if data = session["devise.facebook_data"] && 
                  session["devise.facebook_data"]["extra"]["raw_info"]
            user.email = data["email"] if user.email.blank?
        end
    end
end

omniouth_callbacks_controller

def facebook
    @user = User.from_omniauth(request.env["omniauth.auth"])
    @user.confirmed_at = Time.now
    if @user.persisted?
        sign_in_and_redirect @user, :event => :authentication
        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

一切正常,但如果用户在没有Facebook的情况下注册,然后尝试使用Facebook登录,则不会记录,因为数据库中的表中有用户行。

我想如果用户在没有社交网站的情况下注册并使用Facebook登录,那么这样做,网站个人资料将与Facebook个人资料相关联。 在这种情况下是否内置了Omniouth方法? 如果没有,该怎么做?

0 个答案:

没有答案