Module: LetMeIn::Model

Defined in:
lib/letmein.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/letmein.rb', line 108

def self.included(base)
  base.instance_eval do
    attr_accessor :password
    before_save :encrypt_password
    
    define_method :encrypt_password do
      if password.present?
        p = LetMeIn.accessor(:password, LetMeIn.config.models.index(self.class.to_s))
        s = LetMeIn.accessor(:salt, LetMeIn.config.models.index(self.class.to_s))
        self.send("#{s}=", BCrypt::Engine.generate_salt)
        self.send("#{p}=", BCrypt::Engine.hash_secret(password, self.send(s)))
      end
    end
  end
end