Class: CopDetectiveValidator

Inherits:
Object
  • Object
show all
Includes:
CopDetective::ErrorMessages
Defined in:
lib/validator.rb

Constant Summary collapse

@@messages =
{notice: nil}
@@options_errors =
{option_nil: "is nil.",
empty: "is an empty string."
}

Class Method Summary collapse

Methods included from CopDetective::ErrorMessages

formatting, invalid_password, non_matching, options_error, unsaved_password, wrong_datatype

Class Method Details

.new_passwords_match?(password, confirmation) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/validator.rb', line 26

def new_passwords_match?(password, confirmation)
  password == confirmation
end

.valid_credentials?(user, old_password) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/validator.rb', line 22

def valid_credentials?(user, old_password)
  user.authenticate(old_password) == user
end

.validate_new_passwords(user, password, confirmation) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/validator.rb', line 13

def validate_new_passwords(user, password, confirmation)
  if new_passwords_match?(password, confirmation)
    user.password = password
    @@messages[:notice] = "Password updated"
  else
    user.errors.full_messages << CopDetective::ErrorMessages.unsaved_password(CopDetective::ErrorMessages.non_matching)
  end
end