繁体   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