0
我在需要驗證的應用程序中使用OmniAuth。OmniAuth觸發驗證
我有3種方式對用戶進行身份驗證:
- 我的網站上
- 的Facebook通過OmniAuth
- 的Twitter通過OmniAuth
創建一個賬戶,選擇1我已經驗證的形式爲:
validates_presence_of :email, :role
validates_presence_of :password, :if => :password_required
validates_presence_of :password_confirmation, :if => :password_required
validates_length_of :password, :within => 4..40, :if => :password_required
validates_confirmation_of :password, :if => :password_required
validates_length_of :email, :within => 3..100
validates_uniqueness_of :email, :case_sensitive => false
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
validates_format_of :role, :with => /[A-Za-z]/
問題是,當我允許用戶第一次通過twitter/facebook登錄賬戶時,驗證被觸發並失敗。
例如:
的ActiveRecord :: RecordInvalid - 驗證失敗:密碼不能爲空,密碼太短(最小爲4個字符),確認密碼不能爲空:
這是有道理的,因爲OmniAuth創建的帳戶不會提交密碼,但我不確定我應該如何讓我的模型意識到這一點並跳過(特定?)驗證。
如果它有什麼用途,全account.rb模型是在這裏:http://pastie.org/private/wzpftprrzfg42uifetfhpa
非常感謝!
我找到了一個方法,但我認爲這是一個黑客攻擊。我對此方法做了一個補充(如上面我的pastie所示)。 http://pastie.org/2229023 –