开发者

OmniAuth triggering validations

I am using OmniAuth in an application that requires authentication.

I have 3 ways for users to authenticate:

  1. Create an account on my site
  2. Facebook via OmniAuth
  3. Twitter via OmniAuth

For option 1 I have validations in the form of:

  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]/

The problem is that when I allow a user to login via twitter/facebook for the first time an Account is created, the validations are triggered, and fail.

For example:

ActiveRecord::RecordInvalid - Validation failed: Password can't be blank, Password is too short (minimum is 4 characters), Password confirmation can't be blank:

This makes sense as OmniAuth created accounts will not be submitting a password but i'm not sure exactly how i should make my model aware of this and skip (specific?) validations.

If it's of any use, the full account.rb model is here: http://pastie.org/private/wzpftprrzfg42uifetfhpa

Than开发者_JAVA技巧ks a lot!!


try to extract the condition into the encrypt_password method from here, this line seems incorrect:

  # Callbacks
  before_save :encrypt_password, :if => :password_required

can you also copy-paste stack trace please?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜