Class: DeepThought::User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/deep_thought/models/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



9
10
11
# File 'lib/deep_thought/models/user.rb', line 9

def password
  @password
end

#password_confirmationObject

Returns the value of attribute password_confirmation.



9
10
11
# File 'lib/deep_thought/models/user.rb', line 9

def password_confirmation
  @password_confirmation
end

Class Method Details

.authenticate(email, unencrypted_password) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/deep_thought/models/user.rb', line 21

def self.authenticate(email, unencrypted_password)
  user = find_by_email(email)

  if user && BCrypt::Password.new(user.password_digest) == unencrypted_password
    user
  else
    nil
  end
end

Instance Method Details

#generate_api_keyObject



31
32
33
34
35
# File 'lib/deep_thought/models/user.rb', line 31

def generate_api_key
  uuid = SecureRandom.uuid
  self.api_key = Base64.strict_encode64(uuid)
  self.save!
end