Class: Cyclid::API::User

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

Overview

Model for Users

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#new_passwordObject

Allow an unencryped password to be passed in via. new_password and ensure it is encrypted into password when the record is saved



45
46
47
# File 'app/cyclid/models/user.rb', line 45

def new_password
  @new_password
end

Class Method Details

.all_as_hashObject

Return the collection of Users as an array of Hashes (instead of User objects)



29
30
31
# File 'app/cyclid/models/user.rb', line 29

def all_as_hash
  all.to_a.map(&:serializable_hash)
end

Instance Method Details

#hash_new_passwordObject

Generate a BCrypt2 password from the plaintext



55
56
57
# File 'app/cyclid/models/user.rb', line 55

def hash_new_password
  self.password = BCrypt::Password.create(@new_password)
end

#password_changed?Boolean

Check if the new_password attribute has changed

Returns:

  • (Boolean)


50
51
52
# File 'app/cyclid/models/user.rb', line 50

def password_changed?
  !@new_password.blank?
end