簡體   English   中英

omn​​iauth注冊中帶有必填字段的表單。 (Ruby on Rails)

[英]The form with required fields in omniauth registration. (Ruby on Rails)

我有帶有gem dev + gem omniauthn(多個提供程序)的Rails應用程序。 我遵循了本教程: http : //blog.yangtheman.com/2012/02/09/facebook-connect-with-rails-omniauth-devise/ (應用程序示例: https : //github.com/klebershimabuku/fb_auth_demo

用戶模型:

  devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable
  attr_accessible  :name, :email, :country, :password, :password_confirmation, :remember_me
  has_many :authentications, :dependent => :delete_all

  def apply_omniauth(auth)
    self.email = auth['extra']['raw_info']['email']
    authentications.build(:provider => auth['provider'], :uid => auth['uid'], :token => auth['credentials']['token'])
  end

認證模型:

attr_accessible :provider, :token, :uid, :user_id
belongs_to :user

身份驗證控制器:

def create
    auth = request.env["omniauth.auth"]

    # Try to find authentication first
    authentication = Authentication.find_by_provider_and_uid(auth['provider'], auth['uid'])

    if authentication
      # Authentication found, sign the user in.
      flash[:notice] = "Signed in successfully."
      sign_in_and_redirect(:user, authentication.user)
    else
      # Authentication not found, thus a new user.
      user = User.new
      user.apply_omniauth(auth)
      if user.save(:validate => false)
        flash[:notice] = "Account created and signed in successfully."
        sign_in_and_redirect(:user, user)
      else
        flash[:error] = "Error while creating a user account. Please try again."
        redirect_to root_url
      end
    end
  end

當我用設計表格注冊時,我可以填寫一些必填字段,例如名稱和國家。 但是,當我使用omniauth注冊時,我無法填寫這些字段,因為它根本沒有形式,因此注冊后它們為NULL。 所以我的問題是:如何向omniauth注冊添加帶有必需的額外字段的表單?

Omniauth用於使用其他登錄信息登錄到您的站點-例如從Facebook,Twitter等。

因此,當用戶使用omniauth登錄到您的站點時,您可以從用戶用來登錄到您的站點的站點收集信息。

例如:如果用戶正在使用來自Facebook的登錄名,則可以從用戶用於登錄的站點上收集該城市以及您從該用戶那里獲得的其他信息。 因此,您可以從(偽代碼)獲得更多信息:

 auth['extra']['raw_info']['state']

編輯 :這么說,您可以關注此廣播電視節目中的信息如何向注冊中添加其他字段。

另外,遵循創建設備/ omniauth的另一種方法是遵循此頁面 (只是說)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM