Class: KitsuneUser
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- KitsuneUser
- Defined in:
- lib/kitsune_user.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
Class Method Summary collapse
Instance Method Summary collapse
- #authenticated?(password) ⇒ Boolean
- #encrypt(string) ⇒ Object
- #encrypt_password ⇒ Object
- #generate_hash(string) ⇒ Object
- #initialize_salt ⇒ Object
- #password_required? ⇒ Boolean
- #remember_me! ⇒ Object
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
3 4 5 |
# File 'lib/kitsune_user.rb', line 3 def password @password end |
Class Method Details
.authenticate(email, password) ⇒ Object
45 46 47 48 |
# File 'lib/kitsune_user.rb', line 45 def self.authenticate(email, password) return nil unless user = find_by_email(email) return user if user.authenticated?(password) end |
Instance Method Details
#authenticated?(password) ⇒ Boolean
28 29 30 |
# File 'lib/kitsune_user.rb', line 28 def authenticated?(password) encrypted_password == encrypt(password) end |
#encrypt(string) ⇒ Object
32 33 34 |
# File 'lib/kitsune_user.rb', line 32 def encrypt(string) generate_hash("--#{salt}--#{string}--") end |
#encrypt_password ⇒ Object
36 37 38 39 |
# File 'lib/kitsune_user.rb', line 36 def encrypt_password return if password.blank? self.encrypted_password = encrypt(password) end |
#generate_hash(string) ⇒ Object
13 14 15 |
# File 'lib/kitsune_user.rb', line 13 def generate_hash(string) Digest::SHA1.hexdigest(string) end |
#initialize_salt ⇒ Object
17 18 19 20 21 |
# File 'lib/kitsune_user.rb', line 17 def initialize_salt if new_record? self.salt = generate_hash("--#{Time.now.utc}--#{password}--") end end |
#password_required? ⇒ Boolean
41 42 43 |
# File 'lib/kitsune_user.rb', line 41 def password_required? encrypted_password.blank? || !password.blank? end |
#remember_me! ⇒ Object
23 24 25 26 |
# File 'lib/kitsune_user.rb', line 23 def remember_me! self.remember_token = encrypt("--#{Time.now.utc}--#{password}--#{id}--") save(false) end |