Module: Devise::Models::PasswordHasRequiredContent

Extended by:
ActiveSupport::Concern
Defined in:
lib/devise/secure_password/models/password_has_required_content.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

LENGTH_MAX =
255

Instance Method Summary collapse

Instance Method Details

#validate_password_confirmationObject



31
32
33
34
35
36
37
38
39
# File 'lib/devise/secure_password/models/password_has_required_content.rb', line 31

def validate_password_confirmation
  return true if password_confirmation.nil? # rails skips password_confirmation validation if nil!

  unless password == password_confirmation
    human_attribute_name = self.class.human_attribute_name(:password)
    errors.add(:password_confirmation, :confirmation, attribute: human_attribute_name)
  end
  errors[:password_confirmation].count.zero?
end

#validate_password_confirmation_contentObject



23
24
25
26
27
28
29
# File 'lib/devise/secure_password/models/password_has_required_content.rb', line 23

def validate_password_confirmation_content
  return true if password_confirmation.nil? # rails skips password_confirmation validation if nil!

  errors.delete(:password_confirmation)
  validate_password_content_for(:password_confirmation)
  errors[:password_confirmation].count.zero?
end

#validate_password_contentObject



16
17
18
19
20
21
# File 'lib/devise/secure_password/models/password_has_required_content.rb', line 16

def validate_password_content
  self.password ||= ''
  errors.delete(:password)
  validate_password_content_for(:password)
  errors[:password].count.zero?
end

#validate_password_content_for(attr) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/devise/secure_password/models/password_has_required_content.rb', line 41

def validate_password_content_for(attr)
  return unless respond_to?(attr) && !(password_obj = send(attr)).nil?

  ::Support::String::CharacterCounter.new.count(password_obj).each do |type, dict|
    error_string =  case type
                    when :length then validate_length(dict[:count])
                    when :unknown then validate_unknown(dict)
                    else validate_type(type, dict)
                    end
    errors.add(attr, error_string) if error_string.present?
  end
end