Class: KitsuneUser

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/kitsune_user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#passwordObject

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

Returns:

  • (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_passwordObject



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_saltObject



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

Returns:

  • (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