Module: Huberry::Authentication::ModelMethods

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

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

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
26
27
# File 'lib/huberry/authentication/model_methods.rb', line 6

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