Class: Edgar::User

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

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) password

Returns the value of attribute password



5
6
7
# File 'app/models/edgar/user.rb', line 5

def password
  @password
end

Class Method Details

+ (Object) authenticate(code, password)



28
29
30
31
32
33
34
35
# File 'app/models/edgar/user.rb', line 28

def self.authenticate(code, password)
  user = find_by_code(code)
  if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
    user
  else
    nil
  end
end

+ (Object) view_list_columns

overwrite AR::Base.view_list_columns()



19
20
21
# File 'app/models/edgar/user.rb', line 19

def self.view_list_columns
  %w(id code name created_at updated_at)
end

+ (Object) view_popup_columns

overwrite AR::Base.view_popup_columns()



24
25
26
# File 'app/models/edgar/user.rb', line 24

def self.view_popup_columns
  view_list_columns
end

Instance Method Details

- (Boolean) admin?

Returns:

  • (Boolean)


44
45
46
47
48
# File 'app/models/edgar/user.rb', line 44

def admin?
  user_groups.where(
      kind: Edgar::UserGroup::Kind::ROLE,
      name: 'admin').count > 0
end

- (Object) encrypt_password



37
38
39
40
41
42
# File 'app/models/edgar/user.rb', line 37

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

- (Boolean) password_required? (private)

This method means:

  • When password_hash is not set, password is required.

  • When password is passed from view, it is required to update.

    Matrix is:

    password_hash.blank?
    f t
    ---

    password.blank? f t t

    t f t

Returns:

  • (Boolean)


62
63
64
# File 'app/models/edgar/user.rb', line 62

def password_required?
  password_hash.blank? || !password.blank?
end