新手问题 OmniAuth 怎么实现手机和邮箱都能登陆呢。

sunheyang1993 · 2016年03月28日 · 最后由 sunheyang1993 回复于 2016年03月28日 · 2189 次阅读
class Identity < OmniAuth::Identity::Models::ActiveRecord
  auth_key :email
  attr_accessor :old_password

  MAX_LOGIN_ATTEMPTS = 5

  validates :email, uniqueness: true, email: true, presence: true unless :phone_number?
  validates :phone_number, uniqueness: true, numericality: true, presence: true unless :email?
  validates :password, presence: true, length: { minimum: 6, maximum: 64 }
  validates :password_confirmation, presence: true, length: { minimum: 6, maximum: 64 }


  before_validation :sanitize

  def increment_retry_count
    self.retry_count = (retry_count || 0) + 1
  end

  def too_many_failed_login_attempts
    retry_count.present? && retry_count >= MAX_LOGIN_ATTEMPTS
  end

  private

  def sanitize
    self.email.try(:downcase!)
  end

end

我怎么改都是只能手机登陆或者只能邮箱登陆。怎么能实现都可以登录呢。

可以试着修改下源码

#1 楼 @rudy 怎么查看 OmniAuth 的源码呢。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号