Class: AuthApi::User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/auth_api/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



7
8
9
# File 'app/models/auth_api/user.rb', line 7

def password
  @password
end

Class Method Details

.authenticate(email, password) ⇒ Object



15
16
17
18
# File 'app/models/auth_api/user.rb', line 15

def self.authenticate(email, password)
  user = where(email: email).first
  user and user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt) ? user : nil
end

Instance Method Details

#encrypt_passwordObject



10
11
12
13
# File 'app/models/auth_api/user.rb', line 10

def encrypt_password
  self.password_salt = ::BCrypt::Engine.generate_salt
  self.password_hash = ::BCrypt::Engine.hash_secret(password, password_salt)
end