Module: Huberry::Authentication::ModelMethods::InstanceMethods

Defined in:
lib/huberry/authentication/model_methods.rb

Instance Method Summary collapse

Instance Method Details

#authenticated?(password) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/huberry/authentication/model_methods.rb', line 41

def authenticated?(password)
  send(self.class.authentication_options[:hashed_password_field]) == self.class.digest(password.to_s + send(self.class.authentication_options[:salt_field]).to_s)
end

#password_changed?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/huberry/authentication/model_methods.rb', line 45

def password_changed?
  !!@password_changed
end

#reload_with_authentication(*args) ⇒ Object



49
50
51
52
# File 'lib/huberry/authentication/model_methods.rb', line 49

def reload_with_authentication(*args)
  reload_without_authentication(*args)
  @password_changed = false
end

#reset_password(new_password = nil) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/huberry/authentication/model_methods.rb', line 54

def reset_password(new_password = nil)
  new_password = generate_salt[0..7] if new_password.blank?
  send("#{self.class.authentication_options[:salt_field]}=", nil)
  send("#{self.class.authentication_options[:password_field]}=", new_password)
  send("#{self.class.authentication_options[:password_field]}_confirmation=", new_password)
  @password_changed = true
end

#reset_password!(new_password = nil) ⇒ Object



62
63
64
65
# File 'lib/huberry/authentication/model_methods.rb', line 62

def reset_password!(new_password = nil)
  reset_password(new_password)
  save
end