Class: Challah::PasswordValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
lib/challah/validators/password_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object

Check to make sure a valid password and confirmation were set



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/challah/validators/password_validator.rb', line 4

def validate(record)
  if record.password_provider? or options[:force]
    if record.new_record? and record.password.to_s.blank? and !record.password_changed?
      record.errors.add :password, :blank
    elsif record.password_changed?
      if record.password.to_s.size < 4
        record.errors.add :password, :invalid_password
      elsif record.password.to_s != record.password_confirmation.to_s
        record.errors.add :password, :no_match_password
      end
    end
  end
end