Module: Huberry::Authentication::InstanceMethods

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

Instance Method Summary collapse

Instance Method Details

#authenticated?(password) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#password_changed?Boolean

Returns:

  • (Boolean)


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

def password_changed?
	!!@password_changed
end

#reload_with_authentication(*args) ⇒ Object



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

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

#reset_password(new_password = nil) ⇒ Object



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

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

#reset_password!(new_password = nil) ⇒ Object



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

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