Module: Huberry::Authentication::ModelMethods

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

Instance Method Summary collapse

Instance Method Details

#uses_authentication(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/huberry/authentication/model_methods.rb', line 6

def uses_authentication(options = {})
	extend ClassMethods
	include InstanceMethods
	
	cattr_accessor :hashed_password_field, :login_field, :password_field, :salt_field
	self.hashed_password_field = options[:hashed_password_field] || :hashed_password
	self. = options[:login_field] || :email
	self.password_field = options[:password_field] || :password
	self.salt_field = options[:salt_field] || :salt
	
	attr_accessor self.password_field, "#{self.password_field}_confirmation".to_sym
	
	validates_presence_of self.
		validates_presence_of self.password_field, :if => :password_required?
		validates_confirmation_of self.password_field, :if => :password_required?
	
		before_save :hash_password

	alias_method_chain :reload, :authentication
end