授权twitter(设计宝石,铁轨)的问题

时间:2018-04-14 18:25:37

标签: ruby-on-rails authentication twitter devise

美好的一天。也许我的问题是无稽之谈,但我在推特错误中单挑后:

Devise中的ArgumentError :: RegistrationsController #new

错误的参数数量(给定2,预期为0..1)

我在我的应用程序和其他工作中使用multiply singup

我的回调控制器:

class User < ApplicationRecord

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable,
         :omniauthable, omniauth_providers: %i[google_oauth2 twitter github]

  def self.from_omniauth(auth, _signed_in_resource = nil)
    user = User.where(provider: auth.provider, uid: auth.uid).first
    if user.present?
      user
    else
      user_with_email = User.find_by_email(auth.info.email)
      if user_with_email.present?
        user = user_with_email
      else
        user = User.new

        if auth.provider == 'github'

          user.provider = auth['provider']
          user.uid = auth['uid']

          user.oauth_user_name = auth['info']['name']
          user.email = auth['info']['email']
          user.save

        elsif auth.provider == 'twitter'

          user.provider = auth.provider
          user.uid = auth.uid
          user.oauth_token = auth.credentials.token

          user.oauth_expires_at = auth.extra.raw_info.name


        elsif auth.provider == 'google_oauth2'

          user.provider = auth.provider
          user.uid = auth.uid
          user.oauth_token = auth.credentials.token

          user.first_name = auth.info.first_name
          user.last_name = auth.info.last_name
          user.email = auth.info.email
          user.oauth_expires_at = Time.at(auth.credentials.expires_at)
          user.save
        end
      end
    end
    user
  end

  def self.new_with_session(params, session)
    if session['devise.user_attributes']
      new(session['devise.user_attributes'], without_protection: true) do |user|
        user.attributes = params
        user.valid?
      end
    else
      super
    end
  end

  def password_required?
    super && provider.blank?
  end
end

感谢您的关注和帮助。

0 个答案:

没有答案