Module: CustomFields::Types::Password::Target

Extended by:
ActiveSupport::Concern
Defined in:
lib/custom_fields/types/password.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#_check_password(label, name) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/custom_fields/types/password.rb', line 69

def _check_password(label, name)
  new_password = instance_variable_get(:"@#{name}")
  confirmation = instance_variable_get(:"@#{name}_confirmation")

  return if new_password.blank?

  if new_password.size < CustomFields::Types::Password::Field::MIN_PASSWORD_LENGTH
    errors.add(name, :too_short, count: CustomFields::Types::Password::Field::MIN_PASSWORD_LENGTH)
  end

  return unless confirmation && confirmation != new_password

  errors.add("#{name}_confirmation", :confirmation, attribute: label || name)
end

#_encrypt_password(name, new_password) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/custom_fields/types/password.rb', line 61

def _encrypt_password(name, new_password)
  return if new_password.blank?

  instance_variable_set(:"@#{name}", new_password)

  send(:"#{name}_hash=", BCrypt::Password.create(new_password))
end

#_set_confirmation_password(name, confirmation) ⇒ Object



57
58
59
# File 'lib/custom_fields/types/password.rb', line 57

def _set_confirmation_password(name, confirmation)
  instance_variable_set(:"@#{name}_confirmation", confirmation)
end