设计跳过Facebook的用户确认不起作用

时间:2014-04-02 13:30:36

标签: ruby-on-rails facebook ruby-on-rails-4 oauth devise

设计跳过Facebook的用户确认不起作用。它继续发送电子邮件。

应用/模型/ user.rb

def self.find_for_facebook_oauth(auth, signed_in_resource = nil)
    user = User.where(:provider => auth.provider, :uid => auth.uid).first
    if user
      return user
    else
      registered_user = User.where(:email => auth.info.email).first
      if registered_user
        return registered_user
      else
        user = User.create(name:auth.extra.raw_info.name,
                            provider:auth.provider,
                            uid:auth.uid,
                            email:auth.info.email,
                            password:Devise.friendly_token[0,20]
                          )
        user.skip_confirmation!
        user
      end
    end
  end

我该如何避免这种情况?

1 个答案:

答案 0 :(得分:2)

这应该有效:

def self.find_for_facebook_oauth(auth, signed_in_resource = nil)
  user = User.where(:provider => auth.provider, :uid => auth.uid).first
  if user
    return user
  else
    registered_user = User.where(:email => auth.info.email).first 

    return registered_user if registered_user

    user = User.new(
                   name:auth.extra.raw_info.name,
                   provider:auth.provider,
                   uid:auth.uid,
                   email:auth.info.email,
                   password:Devise.friendly_token[0,20]
           )
      user.skip_confirmation!
      user.save
      user
    end
  end
end

您需要在保存记录之前致电skip_confirmation!